Skip to content

Detect missing comma in function declaration #886

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

Closed

Conversation

flashspys
Copy link
Contributor

This PR will make the Parser capable of detect and recover from a missing comma in a function declaration. The motivating example was the following:

func a(foo: Bar foo2: Bar2) {}

 --- Before Diagnostics
 
 1 │ func a(foo: Bar foo2: Bar2) {}
   ∣                 ╰─ unexpected text 'foo2: Bar2' in parameter clause

 
 --- After Diagnostics
 
 1 │ func a(foo: Bar foo2: Bar2) {}
   ∣                 ╰─ expected ',' in function parameter

@flashspys flashspys requested a review from ahoppen as a code owner October 6, 2022 15:35
Comment on lines +1362 to +1363
var lookahead = self.lookahead()
if lookahead.consume(if: { $0.canBeArgumentLabel }, followedBy: { $0.tokenKind == .colon }) != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I’m not sure if this is the right approach because it break for anything but the most simple arguments. E.g. we wouldn’t enter this recovery case if the argument has modifiers or a secondName. I think you would need to implement a little more sophisticated logic in Lookahead and call that from here.

Also adding test a test case for func foo(first second: Int third fourth: Int) would be good.

@kimdv
Copy link
Contributor

kimdv commented Mar 25, 2025

Closing as #3014 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants