Skip to content

Fix wrong diagnostic for generics #1498

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

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Apr 6, 2023

Fixes #1483

Opened to see if I was on the right path

@kimdv kimdv requested a review from ahoppen as a code owner April 6, 2023 21:51
@kimdv kimdv force-pushed the kimdv/fix-wrong-diagnostic branch 4 times, most recently from 49745e2 to 38aacf4 Compare April 6, 2023 22:11
@kimdv
Copy link
Contributor Author

kimdv commented Apr 6, 2023

@swift-ci please test

@kimdv kimdv force-pushed the kimdv/fix-wrong-diagnostic branch from 38aacf4 to ea628d7 Compare April 7, 2023 07:53
@ahoppen
Copy link
Member

ahoppen commented Apr 7, 2023

I think we should not diagnose this in the parser. A generic parameter list can be represented perfectly well in the SwiftSyntax tree and should thus be diagnosed by later stages of the compilation pipeline.

I should have added that comment to the GitHub issue, sorry. We should fix the crash though.

@kimdv
Copy link
Contributor Author

kimdv commented Apr 9, 2023

@ahoppen I'm not sure I understand.
When debugging this, I looked into the old parser and try to make the same as the old parser.

I think the reason is, because here the current token is <> (a binary operator).
https://github.com/apple/swift-syntax/blob/ac4f8f3ee2d3866152bcd555a62cb8317ea3cb11/Sources/SwiftParser/Declarations.swift#L467

The line after we then consume the token and remap it to <.
Then it crash here because text is not empty, it is <>.
https://github.com/apple/swift-syntax/blob/ac4f8f3ee2d3866152bcd555a62cb8317ea3cb11/Sources/SwiftSyntax/generated/TokenKind.swift#L982-L983

So what I try to do, is only consume the < and then move the lexer to >.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Forget what I said. I was stupid and didn’t read your PR properly, I’m sorry.

I thought you had added code in ParseDiagnosticGenerator that detected empty generic argument lists but that’s just not what you did. Looking at your PR again, it looks good, I’m just wondering why you can’t use consumePrefix.

@kimdv kimdv force-pushed the kimdv/fix-wrong-diagnostic branch from ea628d7 to e86341c Compare April 12, 2023 06:22
@kimdv kimdv force-pushed the kimdv/fix-wrong-diagnostic branch from e86341c to fd3a8c5 Compare April 12, 2023 19:41
@kimdv
Copy link
Contributor Author

kimdv commented Apr 12, 2023

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Apr 13, 2023

@swift-ci please test windows

@kimdv kimdv enabled auto-merge April 13, 2023 06:43
@kimdv kimdv merged commit c2734b5 into swiftlang:main Apr 13, 2023
@kimdv kimdv deleted the kimdv/fix-wrong-diagnostic branch April 13, 2023 10:31
kimdv added a commit to kimdv/swift-syntax that referenced this pull request Apr 13, 2023
kimdv added a commit to kimdv/swift-syntax that referenced this pull request Apr 23, 2023
ahoppen pushed a commit to ahoppen/swift-syntax that referenced this pull request Apr 24, 2023
ahoppen pushed a commit to ahoppen/swift-syntax that referenced this pull request Apr 24, 2023
ahoppen pushed a commit to ahoppen/swift-syntax that referenced this pull request Apr 25, 2023
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.

Empty generic parameter clause produces no diagnostic
2 participants