Skip to content

Parse an ellipsis T... for type parameter packs #948

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 3 commits into from
Oct 15, 2022

Conversation

hamishknight
Copy link
Contributor

In a generic parameter list, parse an ellipsis to produce a type parameter pack. This replaces the previous @_typeSequence attribute.

In a generic parameter list, parse an ellipsis
to produce a type parameter pack. This replaces
the previous `@_typeSequence` attribute.
This is no longer needed now that we have the
ellipsis spelling.
@hamishknight
Copy link
Contributor Author

swiftlang/swift#61575

@swift-ci please test

@hamishknight hamishknight merged commit 4573ba7 into swiftlang:main Oct 15, 2022
@hamishknight hamishknight deleted the etc branch October 15, 2022 09:53
Comment on lines +1123 to +1129
// Detect an attempt to use a type parameter pack.
var unexpectedAfterName: RawUnexpectedNodesSyntax?
if let ellipsis = tryConsumeEllipsisPrefix() {
unexpectedAfterName = RawUnexpectedNodesSyntax(
elements: [RawSyntax(ellipsis)], arena: self.arena)
}

Copy link
Member

Choose a reason for hiding this comment

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

There is a convenience initializer on RawUnexpectedNodesSyntax that fails if it is passed only nil elements, so this can be simplified to

let ellipsis = tryConsumeEllipsisPrefix()

and then below where you are currently passing unexpectedAfterName to the RawAssociatedtypeDeclSyntax initializer:

RawUnexpectedNodesSyntax(ellipsis, arena: self.arena)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat!

@@ -145,6 +145,29 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
addDiagnostic(incorrectContainer, message(misplacedTokens), fixIts: fixIts, handledNodes: [incorrectContainer.id] + correctAndMissingTokens.map(\.id))
}

/// Utility function to remove a misplaced token with a custom error message.
Copy link
Member

Choose a reason for hiding this comment

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

If you agree, I think the following comment is a little more descriptive.

/// If `unexpected` only contains a single token that satisfies `predicate` emit a diagnostic with `message` that removes this token.

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