-
Notifications
You must be signed in to change notification settings - Fork 441
Detect and recover from missing comma in tupel #898
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
ahoppen
merged 1 commit into
swiftlang:main
from
flashspys:detect-missing-comma-in-tupel
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we have to "reparse" an already as identifier parsed token as a type. I'm not quite sure if there is a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t see any issues here in wrapping
first
in aRawSimpleTypeIdentifierSyntax
but because we won’t be parsing generic types likeArray<Int>
correctly here. It would also be worth adding test cases for this, I think.What I don’t understand here, is why we are wrapping
first
here. For(foo Bar)
doesn’t this result in two tuple elements, one that only has a label and one that only has a type but no label? I think we should be forming a single tuple element, that has a namefoo
, missing colon and typeBar
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we visit this code only if first was set above, and this is only the case if
self.lookahead().startsParameterName(false)
is true, first must be an argument label (and thus, always a RawSimpleTypeIdentifierSyntax), this code does not apply for things likeArray<Int>
I added some test cases for generic types
For
(foo Bar)
we start to look for an argument label (first
), an optional second argument label (second
), and a colon. If we found first (foo
), but no second and no colon, we are in the case where we must decide iffoo
is an identifier and a colon is missing or a type and a comma is missing. In the first case we don't visited the commented code and proceed to parseBar
as a type. But if we think a comma is missing we must convert first (already parsed as an argument label) to a type.Bar
now has to be parsed as a type, too, but as a separateRawTupleTypeElementSyntax
, thus we cannot proceed with the current loop here, but we have tocontinue
the loop and start the "tuple element parsing" onBar
again, resulting in two separateRawTupleTypeElementSyntax
, with the first one missing a comma. To summarize: Is first uppercase, finish thisRawTupleTypeElementSyntax
directly, if not, proceed thisRawTupleTypeElementSyntax
.This is exactly what's happening here if this code is not visited, respectively,
foo
is not uppercase.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. That makes sense. 👍
Thank you 🙏
Oh, I know what my misunderstanding was. I thought we were parsing tuples in patterns (as in
let (a, b) = foo()
) here, but this is for tuple types. In that case everything makes sense 👍