Skip to content

[Variadic Generics] type parameter pack syntax change: T... -> each T #1384

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
Mar 3, 2023

Conversation

sophiapoirier
Copy link
Contributor

No description provided.

@sophiapoirier sophiapoirier force-pushed the pack-type-syntax-each branch from e25bc79 to 4a92c6e Compare March 2, 2023 22:53
@sophiapoirier
Copy link
Contributor Author

swiftlang/swift#64039

@swift-ci please test

@sophiapoirier sophiapoirier merged commit df3d681 into swiftlang:main Mar 3, 2023
let each = self.consume(if: .keyword(.each))

let (unexpectedBetweenEachAndName, name) = self.expectIdentifier()
if attributes == nil && unexpectedBetweenEachAndName == nil && name.isMissing && elements.isEmpty {
Copy link
Member

Choose a reason for hiding this comment

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

You need to check that each is nil here as well, otherwise we could drop each and not round-trip. A test case that currently fails should be if you open a generic argument list, write each and then reach the end of the file, i.e.

func foo<each

Copy link
Contributor Author

Choose a reason for hiding this comment

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

each is supposed to be optional/nullable because the absence of each indicates a standard generic type parameter and the presence of each indicates a variadic type parameter pack. This was the case before my PR as well except prior to my syntax change, it was postfix ellipsis that made the distinction rather than the preceding each. Admittedly I do not know what is meant by "we could drop each and not round-trip"?

Copy link
Contributor

Choose a reason for hiding this comment

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

swift-syntax preserves each token in the source file in the parse tree as it was written, even if you hav something invalid like each not followed by a type parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @ahoppen , I have addressed this in my follow-up PR #1393

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.

4 participants