Skip to content

Add support for '@retroactive' conformances in SwiftSyntaxParser #2275

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 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public enum Keyword: CaseIterable {
case `repeat`
case required
case `rethrows`
case retroactive
case `return`
case reverse
case right
Expand Down Expand Up @@ -611,6 +612,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("required")
case .rethrows:
return KeywordSpec("rethrows", isLexerClassified: true)
case .retroactive:
return KeywordSpec("retroactive")
case .return:
return KeywordSpec("return", isLexerClassified: true)
case .reverse:
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ enum TokenPrecedence: Comparable {
.noDerivative,
.noescape,
.Sendable,
.retroactive,
.unchecked:
self = .exprKeyword

Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftParser/TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ enum TypeAttribute: TokenSpecSet {
case escaping
case noDerivative
case noescape
case retroactive
case Sendable
case unchecked

Expand All @@ -646,6 +647,7 @@ enum TypeAttribute: TokenSpecSet {
case TokenSpec(.noDerivative): self = .noDerivative
case TokenSpec(.noescape): self = .noescape
case TokenSpec(.Sendable): self = .Sendable
case TokenSpec(.retroactive): self = .retroactive
case TokenSpec(.unchecked): self = .unchecked
default: return nil
}
Expand All @@ -663,6 +665,7 @@ enum TypeAttribute: TokenSpecSet {
case .escaping: return .keyword(.escaping)
case .noDerivative: return .keyword(.noDerivative)
case .noescape: return .keyword(.noescape)
case .retroactive: return .keyword(.retroactive)
case .Sendable: return .keyword(.Sendable)
case .unchecked: return .keyword(.unchecked)
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ extension Parser {

mutating func parseTypeAttribute() -> RawAttributeListSyntax.Element {
switch peek(isAtAnyIn: TypeAttribute.self) {
case ._local, ._noMetadata, .async, .escaping, .noDerivative, .noescape, .Sendable, .unchecked, .autoclosure:
case ._local, ._noMetadata, .async, .escaping, .noDerivative, .noescape,
.retroactive, .Sendable, .unchecked, .autoclosure:
// Known type attribute that doesn't take any arguments
return parseAttributeWithoutArguments()
case .differentiable:
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public enum Keyword: UInt8, Hashable {
case `repeat`
case required
case `rethrows`
case retroactive
case `return`
case reverse
case right
Expand Down Expand Up @@ -620,6 +621,8 @@ public enum Keyword: UInt8, Hashable {
self = .nonisolated
case "nonmutating":
self = .nonmutating
case "retroactive":
self = .retroactive
case "unavailable":
self = .unavailable
default:
Expand Down Expand Up @@ -940,6 +943,7 @@ public enum Keyword: UInt8, Hashable {
"repeat",
"required",
"rethrows",
"retroactive",
"return",
"reverse",
"right",
Expand Down
8 changes: 8 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ final class DeclarationTests: ParserTestCase {
)
}

func testParseRetroactiveExtension() {
assertParse(
"""
extension Int: @retroactive Identifiable {}
"""
)
}

func testParseDynamicReplacement() {
assertParse(
"""
Expand Down