-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript #6863
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
Conversation
…alizer, deinitializer, or subscript Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages. Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
Would you mind reviewing this when you get a chance? Thanks! |
struct A0 { | ||
subscript // expected-error{{expected '(' for subscript parameters}} | ||
subscript // expected-error {{subscripts cannot have a name}} {{5-7=}} | ||
i : Int |
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 interesting; because of the following colon, we ought to realize that it's parens that are missing, not a spurious name being added. I'm not sure this is a net improvement in this case.
Mind checking for a colon too? That would help initializers as well, though less so since init foo bar : Int
could be a mistake for init foo(bar: Int)
or init(foo bar: Int)
.
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.
Maybe it’s preferable to treat init foo bar : Int
as a mistake for int(foo bar : Int)
, since adding the parens would make the syntax valid. If so, I can restrict this diagnostic to require a following paren, and let the existing one handle that case (and do the same for subscripts). What do you think? (No problem if not. I can check for a colon following the identifier.)
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.
Your way seems reasonable. Thanks, Matthew!
if (Tok.is(tok::identifier)) { | ||
diagnose(Tok, diag::destructor_has_name).fixItRemove(Tok.getLoc()); | ||
} | ||
else { |
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.
Nitpick: we put else on the same line as } and generally avoid single-statement blocks
@swift-ci Please smoke test |
…alizer, deinitializer, or subscript - Restrict this diagnostic to identifiers that are followed by a left paren.
I added a check for identifiers that are followed by a left paren, added some tests, and fixed the code style issues. |
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.
Looks good. Thanks, Matthew!
@swift-ci Please smoke test |
Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages.
Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
https://bugs.swift.org/browse/SR-3600