Skip to content

Add diagnostic for wrong specialize label #1727

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 4 commits into from
Aug 5, 2023

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Jun 3, 2023

Resolves #1605

@kimdv kimdv requested a review from ahoppen as a code owner June 3, 2023 21:41
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch 2 times, most recently from e591f32 to 6516f9f Compare June 3, 2023 21:48
@kimdv kimdv mentioned this pull request Jun 7, 2023
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch 2 times, most recently from b104ce1 to 4ddfa36 Compare June 12, 2023 18:38
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 4ddfa36 to 343c511 Compare June 19, 2023 19:46
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 343c511 to 235f328 Compare June 22, 2023 17:37
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 235f328 to 717ac51 Compare July 8, 2023 14:54
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Jul 10, 2023
This fixes a couple of formatting issues and resolves the question raised in swiftlang#1727 (comment).
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Jul 10, 2023
This fixes a couple of formatting issues and resolves the question raised in swiftlang#1727 (comment).
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Jul 11, 2023
This fixes a couple of formatting issues and resolves the question raised in swiftlang#1727 (comment).
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 717ac51 to 8af7673 Compare July 19, 2023 09:40
@kimdv kimdv requested a review from ahoppen July 19, 2023 09:53
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 8af7673 to f7b4439 Compare July 19, 2023 10:06
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

@kimdv kimdv enabled auto-merge July 19, 2023 15:36
@kimdv
Copy link
Contributor Author

kimdv commented Jul 19, 2023

@swift-ci please test

@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch 2 times, most recently from 7aaaaf3 to 5befba8 Compare July 31, 2023 17:44
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.

I’d like one more doc comment after reading this with a few days break, otherwise LGTM.

@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 5befba8 to 489a750 Compare August 1, 2023 07:10
@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch 3 times, most recently from 8b1159e to c06e3cf Compare August 2, 2023 13:30
@ahoppen
Copy link
Member

ahoppen commented Aug 3, 2023

@swift-ci Please test

@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from c06e3cf to 9f94aff Compare August 4, 2023 15:15
Comment on lines 94 to 97
@_specialize(e:) <#declaration#>
@_specialize() <#declaration#>; e
Copy link
Contributor Author

@kimdv kimdv Aug 4, 2023

Choose a reason for hiding this comment

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

@ahoppen I did a bit of digging for this issue we breaifly talked about here.
What I can see is, that after calling self.expect(.leftParen) then the current token is e we don't consume it, as e is not a label in @_spacialize(
We then try to find the precedence of the current token. e is an identifier, thus there are none.

Thats why we get this result I think

testMissingClosingParenToAttribute(): failed - Actual output (+) differed from expected output (-):
–@_specialize(e:) <#declaration#>
+@_specialize() <#declaration#>; e

The parser tries to parse the label e and don't know it, so we break out if the loop as you suggested.
So I think it's doing its work correctly (for now)
But it would be more nice if we did consume e as unknown label, and then apply a fixit that suggest to make one if the ones defined in the token set.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, what I missed here is that there is no closing ) in the test case. If the input was @_specialize(e) (which is what I thought, I just didn’t check carefully), then expect(.rightParen) would eat the e as unexpected and recover to ). So, I agree that the current recovery is consistent and makes sense for now.

Also, this test case is a little degenerate because it doesn’t have a declaration following the attribute. If you make it a little bit more realistic like

@_specialize(e
func foo() {}

then the fixed source is

@_specialize()e
func foo() {}

Putting the e outside the parentheses makes as much sense as putting it inside, so I think it’s fine and there’s nothing we need to do.

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.

One more comment that I forgot last time, otherwise LGTM. Let’s merge this after 2 months 😉

@kimdv kimdv force-pushed the kimdv/fix-specialize-error branch from 9f94aff to 11cffa3 Compare August 4, 2023 21:39
@kimdv
Copy link
Contributor Author

kimdv commented Aug 4, 2023

@swift-ci please test

@kimdv
Copy link
Contributor Author

kimdv commented Aug 4, 2023

@swift-ci please test windows

@kimdv kimdv merged commit aa54b10 into swiftlang:main Aug 5, 2023
@kimdv kimdv deleted the kimdv/fix-specialize-error branch August 5, 2023 02:40
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.

Wrong diagnostics for _specialize attribute
2 participants