Skip to content
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

[SR-12583] foo() {} {} parses but foo {} {} does not #55028

Open
jckarter opened this issue Apr 14, 2020 · 7 comments
Open

[SR-12583] foo() {} {} parses but foo {} {} does not #55028

jckarter opened this issue Apr 14, 2020 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers

Comments

@jckarter
Copy link
Contributor

Previous ID SR-12583
Radar rdar://problem/62202372
Original Reporter @jckarter
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: f3208365889a29361424efaa2b6814cd

Issue Description:

If you have a function that takes a function, then returns a function that takes another function:

func foo(_: ()->()) -> (() -> ()) -> () { fatalError() }

Then you can call it like this:

foo() {} {}

but this doesn't parse:

foo {} {}
@lattner
Copy link
Mannequin

lattner mannequin commented Apr 14, 2020

facepalm Trailing closures really need to be tied to the syntactic form of the callee, neither of those should be allowed IMO.

Perhaps for Swift 6...

-Chris

@ApolloZhu
Copy link
Contributor

Just to contribute another test case: `foo {} () {}` parses

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2020

Comment by Daniel Sweeney (JIRA)

I've been looking at this a little. Dumping the parse of both of the bad forms above comes out as

        (call_expr 
          (call_expr 
            (paren_expr trailing-closure))
          (paren_expr trailing-closure)) 

(eliding some stuff in the tree).

If you checked when the second trailing-closure is parsed whether you were in the matching structure (with a call_expr/paren=trailing closure sibling in the call_expr you belong to, oversimplified) you could catch both the syntax problems above.

I was trying to figure out how to do this in code though. SwiftParse/ParseExpr.cpp/ParseExprList is where it parses the trailing closure but that does not feel like the right place in code–other places in SwiftParse don't seem to be matching on structure to find things (I might be wrong) unless they are looking immediately forward in the parse stream.

Is there someplace where it would make sense to put this check? It feels like something that makes sense in the type checker but it's checking syntax. Or am I worrying about it too much?

@swift-ci
Copy link
Contributor

Comment by Daniel Sweeney (JIRA)

I put together a pull request for this: #32000 .

@swift-ci
Copy link
Contributor

Comment by Daniel Sweeney (JIRA)

I closed the pull request for now. We can open it back up at some point if we decide about the source-breaking change. I'm going to un-assign this as well, but I can take it back on.

@jckarter
Copy link
Contributor Author

Thanks dfsweeney (JIRA User)! I'll see if I can get the core team to make a decision on this in one of our meetings soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants