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-12856] Swift rejects valid array type literal containing closure #55302

Open
nicklockwood opened this issue May 22, 2020 · 4 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself parser Area → compiler: The legacy C++ parser

Comments

@nicklockwood
Copy link
Contributor

Previous ID SR-12856
Radar None
Original Reporter @nicklockwood
Type Bug
Environment

Swift 5.2, Xcode 11.4

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, Parser
Assignee None
Priority Medium

md5: 6b3b7fd38d8c9ac6fbf92e4492b5844f

Issue Description:

The following code is rejected by the Swift compiler with the error message "Expected ',' separator":

var handlers = [(_ image: Data?) -> Void]()

However the following all work:

var handlers: [(_ image: Data?) -> Void]
var handlers = Array<(_ image: Data?) -> Void>()
var handlers = [(image: Data?) -> Void]()
var handlers = [(Data?) -> Void]()
@nicklockwood
Copy link
Contributor Author

It also fails with the same error for Dictionary and Optional literals:

var handlers = [String: (_ image: Data?) -> Void]()
var handler = ((_ image: Data?) -> Void)?

@theblixguy
Copy link
Collaborator

It doesn't seem like it is limited to function types - var handlers = [(_ image: Data?)]() throws a similar error.

@nicklockwood
Copy link
Contributor Author

But

(_ image: Data?)

isn't a valid type though. Tuple labels cannot be prefixed with `_` to make them anonymous (nor would it really make sense to do so).

The bug seems to be specifically triggered by using `_` for anonymous arguments in closures.

@theblixguy
Copy link
Collaborator

Yes, I was just referring to the diagnostic being the same (i.e expected ',' separator) which seems wrong here. I think in either scenarios it's trying to parse it as a discard assignment expression and failing.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 in itself parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

2 participants