-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-12583] Added checks to catch 'foo() {} {}' and 'foo {} () {}' #32000
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
Thank you for tackling this!
If we diagnose this, yes, the parser is the right place.
At least in the current grammar, they should be valid syntax.
It should be "OK" because multiple trailing closures require argument labels. For example
For now, we shouldn't disallow any currently accepted syntax. So @dfsweeney, could you consider changing parser to accept |
I think I misunderstood Chris's comments and thought that we should prevent the parse, so that's what I put in the code in this PR (assuming the code actually does that, haha). It makes sense for expr {} {} to parse consistently--I will look at allowing that. Should I close this PR? I think allowing expr {} {} to parse as above probably touches different code--I could make a new PR for that once I identify it. What do you think? |
Disallowing any form seems in line with the "spirit" if not the letter of the grammar, but it would be a source-breaking change. I'll bring this up with the Core Team to decide what the best approach is. |
@swift-ci Please test source compatibility |
I'm going to close this one for now. I have the code if we want to bring it back up at some point. It did not take that long to do and I learned a bunch of stuff. |
Addresses two parse problems in SR-12583, where (single) trailing closures should not be parsed in the neighborhood of other trailing closures. The parse trees for both forms are identical but the Parser takes two paths to get there. @jckarter entered the original bug.
Several questions:
Is this the right place/method to do this? I just put an if(condition) check in two places in the parser and emitted a diagnostic. Should the check be in the CallExpr::create() instead of in the parser?
I'm not completely sure that there's not a valid parse like this. The parse tree looks like the below. It indents poorly here but it's a call with a trailing closure containing another call with a trailing closure. I'm still thinking through whether there's some legitimate Swift code that could generate that:
(call_expr (call_expr (paren_expr trailing-closure)) (paren_expr trailing-closure))
The diagnostic just says 'double trailing closures' right now, which is accurate but not clear enough. Any suggestions to improve the wording are welcome. I will think about it further.
This may interfere or interact with work on multiple trailing closures that @xedin (I think) is working on now.
The swift in the examples is kind of aesthetically displeasing but logically OK. I'm not sure this should actually be disallowed.
Resolves SR-12583.