-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parse][SR-510] emit error for closures outside of a func #934
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
When there is no local context, we should emit an error rather than silently eating the closure. This code used to be silent to avoid double-reporting an error for fixed-size array types, but those no longer exist.
Passes (except for the existing failing test on master at the moment, not related to this PR.) |
Thanks, @dduan! |
The error message isn't really correct for a user:
Stepping back, both of the other test changes aren't really adding any value. Admittedly those are just a mess of tokens and therefore a mess of error messages, but a user who ends up in that situation is probably not thinking of those braced-blocks as closures. Why isn't this being caught by the normal enum case expression validation already? |
@jrose-apple For enum rawValue, the enum expression parser simply gives |
@jrose-apple for comparison, I attempted to catch the error at the enum error but ultimately decided solution here is better. #931 Part of this bug is when rawValue parsing fails, the case expression code simply quit silently. That's probably worth addressing too. |
@jrose-apple Thanks for the feedback. I agree that the error message is not great, but had missed some of your points. I believe the way the current logic for parsing the raw values works is that parseExpr will always print an error message when it fails, falling back to the generic "expected raw case value" error if it is completely confused. If parseExpr succeeds parsing an expression, then the case parseDeclEnumCase validates that it is a literal, etc (which I think you're referring to about the case validation). In this case the expression was failing to parse at all, but parseExpr was not producing an error. So, it seems like we could:
I personally think that the second option is probably the most reasonable, but it is currently unprecedented (the "fallback" diagnostic is only emitted in a single place right now) which is why I didn't do it in the first place. What do you think? |
Hm. What about just making a local context? I haven't looked at this code recently so I don't know how hard that is, but it seems like just parsing case values the same way as property initial values would be reasonable. |
Sure, I can look into that. |
@dduan If you'd like to take a look at that yourself, feel free to grab the bug from me. |
When there is no local context, we should emit an error rather than
silently eating the closure. This code used to be silent to avoid
double-reporting an error for fixed-size array types, but those
no longer exist.
Resolves https://bugs.swift.org/browse/SR-510