swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Improve diagnostic for unnamed closure parameter

Open AnthonyLatsis opened this issue 1 year ago • 3 comments

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.

AnthonyLatsis avatar Nov 08 '23 09:11 AnthonyLatsis

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

ahoppen avatar Nov 08 '23 11:11 ahoppen

Could I be assigned the issue? Thanks!

michaelleejl avatar Nov 08 '23 19:11 michaelleejl

To clarify: The C++ parser used to emit a warning for this and is changed in https://github.com/apple/swift/pull/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

ahoppen avatar Nov 29 '23 03:11 ahoppen