Skip to content

Fix error message when type argument arity is wrong #28366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 11, 2018

Conversation

pesca
Copy link
Contributor

@pesca pesca commented Nov 6, 2018

Fixes #28053

  • I decided to forgo addressing the plurals issue to avoid polluting Diagnostics.json with all the different permutations of the error messages. I believe that should ideally be handled in the "diagnostic emitter".
  • Generic functions with no overloads are handled as a special case and uses the old error message.

@ghost ghost requested a review from DanielRosenwasser November 6, 2018 17:27
@DanielRosenwasser
Copy link
Member

Looks good; can you resolve the merge conflict, and also make it argument(s)?

@pesca
Copy link
Contributor Author

pesca commented Nov 14, 2018

@DanielRosenwasser Merge conflict resolved.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think fixing this bug does more harm than good. The current implementation is not confusing when it's wrong, and is not commonly wrong. Opinions @DanielRosenwasser ?

If we decide to take this, the change is technically solid but the wording is prolix. I'd like to keep the current terse style.

@@ -2012,7 +2012,7 @@
"category": "Error",
"code": 2557
},
"Expected {0} type arguments, but got {1}.": {
"Expected {0} type argument(s), but got {1}.": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just adds visual noise. Please revert it.

}
const paramCount = min === max ? min : min + "-" + max;
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length);
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.No_overload_expects_0_type_argument_s_but_an_overload_does_exist_that_expects_1_type_argument_s, argCount, belowArgCount === -Infinity ? aboveArgCount : belowArgCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this to the previous message? The only reason I see for the new message is that before, the expected was either min or min–max. Now expected is either above or below, but above is the common case anyway, and means basically the same as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is consistent with the other new message when there are overloads, but I suppose the old message is fine as well.

@sandersn
Copy link
Member

Follow up: I discovered that this is a follow-up to #24031, which does the same thing for parameters instead of type parameters. I don't think that was a good change either, but a lot of people upvoted the bug. I think the reason fewer people upvoted this one is that it's much more rare with type parameters.

Anyway, consistency is one good argument for merging this since we already have this error for parameters. That means my last comment is moot because that error message is the same as the parameter one.

@pesca
Copy link
Contributor Author

pesca commented Dec 11, 2018

Requested changes made.

@sandersn sandersn merged commit e6aa992 into microsoft:master Dec 11, 2018
@fatcerberus
Copy link

not confusing when it’s wrong

@sandersn As a developer I would argue that this:

Expected 0-2 type arguments, but got 1.

is plenty confusing. Imagine if instead of “0-2” it was “0-4” but the only legal arities were exactly 0 and exactly 4. You’d have to see the complete list of overloads to know what went wrong.

On a related note, I had no idea generics could be overloaded until I saw this issue. Learn something new every day...

@DanielRosenwasser
Copy link
Member

@fatcerberus yup, the error messages have been corrected and now give a better idea of what went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants