-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
clarify why we're suggesting removing semicolon after braced items #51955
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is of course very opinionated, but what do you think about replacing the
expected item, found ;
message with this message?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm negatively disposed. We're trying to make inferences about the user's state of mind and helpfully remind them how the language works (in contrast to other languages that we think they might be confusing us with). It's a good magical thing to do, but I think it would be overstepping the mandate of the parser to make it the top-line message rather than an ancillary note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a question of numbers. If most ppl add semicolons because they think the definitions need one, then the error should reflect that. Sadly we don't have numbers...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the issue was about changing the error message ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk
While I'm happy to defer to the authority of you or other team members, I don't think numbers are very relevant to the distinction I was trying to draw in my previous comment.
For a perhaps clearer-cut case, consider what we emit when someone tries to destructure a tuple using comma-separated values and no parentheses (e.g.,
let a, b = (1, 2);
). In that case, I think it's appropriate that the top-line error is "unexpected,
in pattern", and only the ancillary suggestion suggests adding parentheses: the former message says what went wrong with parsing (there's nothing in the grammar that lets you put a comma there) while being agnostic about what could have motivated someone to write that code, and then, that having been established, we go on to provide a helpful suggestion that maybe you meant to use parentheses. Even if (as seems likely), among people who encounter this error, a solid majority of them geniunely wanted a tuple-unpacking and didn't think parens were necessary, and only a tiny minority just happened to have their fingers slip and insert a comma for no reason, it still makes sense to have both messages in that order, because they're serving different functions: flagging the parsing error is distinct from pointing out what misunderstanding of the language might have motivated that error, and the former should come first because it's an analytic truth, whereas the latter is fundamentally only a guess, though a very high-probability guess it may be. I think the same phenomenon is going on here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we definitely err on the safe side by keeping the "expected,found" error. You're right that it would be a major change to diagnostics and should not be done lightly