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

Improve diagnostic for unnamed closure parameter #2340

Open
AnthonyLatsis opened this issue Nov 8, 2023 · 3 comments
Open

Improve diagnostic for unnamed closure parameter #2340

AnthonyLatsis opened this issue Nov 8, 2023 · 3 comments
Assignees
Labels
bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift

Comments

@AnthonyLatsis
Copy link
Contributor

Issue Kind

Bad Diagnostic Produced

Source Code

test { ([X]) in }

Description

New parser:

error: unexpected code '[X]' in parameter clause
test { ([X]) in }
        ^~~

Old parser:

warning: unnamed parameters must be written with the empty name '_' [parameter_unnamed_warn]
test { ([X]) in }
        ^
        _:

This is a special case. More generally, the old parser is capable of diagnosing this kind of closure parameter production gracefully when all of the following are true:

  • An argument name cannot be parsed (link)
  • A type can be parsed per Parser::canParseType(), and said type is followed by ,, ), or = (link)

Related to #2331.

@ahoppen
Copy link
Collaborator

ahoppen commented Nov 8, 2023

Tracked in Apple’s issue tracker as rdar://118109912

@michaelleejl
Copy link

Could I be assigned the issue? Thanks!

@ahoppen ahoppen changed the title Bad diagnostic for explicit parameter type with missing parameter name in closure parameter New parser does not accept closure parameter only consisting of a type Nov 9, 2023
@ahoppen ahoppen changed the title New parser does not accept closure parameter only consisting of a type Improve diagnostic for unnamed closure parameter Nov 28, 2023
@ahoppen
Copy link
Collaborator

ahoppen commented Nov 29, 2023

To clarify: The C++ parser used to emit a warning for this and is changed in apple/swift#70065 to instead emit an error. The new parser should also emit an error but one that is nicer than the currently emitted unexpected code '[X]' in parameter clause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift
Projects
None yet
Development

No branches or pull requests

3 participants