Skip to content

Commit f2b149e

Browse files
authored
Merge pull request #1560 from kavon/5.9-without-operator
[5.9🍒] without operator using `~` for implicit conformance suppression
2 parents 27cd619 + b51216b commit f2b149e

File tree

18 files changed

+417
-24
lines changed

18 files changed

+417
-24
lines changed

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ public let TYPE_NODES: [Node] = [
349349
]
350350
),
351351

352+
// suppressed-type -> '~' type
353+
Node(
354+
name: "SuppressedType",
355+
nameForDiagnostics: "suppressed type conformance",
356+
kind: "Type",
357+
children: [
358+
Child(
359+
name: "WithoutTilde",
360+
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")])
361+
),
362+
Child(
363+
name: "PatternType",
364+
kind: .node(kind: "Type")
365+
),
366+
]
367+
),
368+
352369
// pack-expansion-type -> type '...'
353370
Node(
354371
name: "PackExpansionType",

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension Parser {
497497
let unexpectedBeforeInherited: RawUnexpectedNodesSyntax?
498498
let inherited: RawTypeSyntax?
499499
if colon != nil {
500-
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) {
500+
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) || self.atContextualPunctuator("~") {
501501
unexpectedBeforeInherited = nil
502502
inherited = self.parseType()
503503
} else if let classKeyword = self.consume(if: .keyword(.class)) {

Sources/SwiftParser/Types.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ extension Parser {
3737
)
3838
}
3939

40+
// Parse without operator preceding a type '~ T'.
41+
if let withoutTilde = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator) {
42+
let type = self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
43+
return RawTypeSyntax(
44+
RawSuppressedTypeSyntax(
45+
withoutTilde: withoutTilde,
46+
patternType: type,
47+
arena: self.arena
48+
)
49+
)
50+
}
51+
4052
return self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
4153
}
4254

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ extension SyntaxKind {
341341
return "subscript"
342342
case .subscriptExpr:
343343
return "subscript"
344+
case .suppressedType:
345+
return "suppressed type conformance"
344346
case .switchCase:
345347
return "switch case"
346348
case .switchExpr:

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
186186
- <doc:SwiftSyntax/PackExpansionTypeSyntax>
187187
- <doc:SwiftSyntax/PackReferenceTypeSyntax>
188188
- <doc:SwiftSyntax/SimpleTypeIdentifierSyntax>
189+
- <doc:SwiftSyntax/SuppressedTypeSyntax>
189190
- <doc:SwiftSyntax/TupleTypeSyntax>
190191

191192
### Collections

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,16 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
28692869
return "superKeyword"
28702870
case \SuperRefExprSyntax.unexpectedAfterSuperKeyword:
28712871
return "unexpectedAfterSuperKeyword"
2872+
case \SuppressedTypeSyntax.unexpectedBeforeWithoutTilde:
2873+
return "unexpectedBeforeWithoutTilde"
2874+
case \SuppressedTypeSyntax.withoutTilde:
2875+
return "withoutTilde"
2876+
case \SuppressedTypeSyntax.unexpectedBetweenWithoutTildeAndPatternType:
2877+
return "unexpectedBetweenWithoutTildeAndPatternType"
2878+
case \SuppressedTypeSyntax.patternType:
2879+
return "patternType"
2880+
case \SuppressedTypeSyntax.unexpectedAfterPatternType:
2881+
return "unexpectedAfterPatternType"
28722882
case \SwitchCaseLabelSyntax.unexpectedBeforeCaseKeyword:
28732883
return "unexpectedBeforeCaseKeyword"
28742884
case \SwitchCaseLabelSyntax.caseKeyword:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,14 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
18691869
visitAnyPost(node._syntaxNode)
18701870
}
18711871

1872+
override open func visit(_ node: SuppressedTypeSyntax) -> SyntaxVisitorContinueKind {
1873+
return visitAny(node._syntaxNode)
1874+
}
1875+
1876+
override open func visitPost(_ node: SuppressedTypeSyntax) {
1877+
visitAnyPost(node._syntaxNode)
1878+
}
1879+
18721880
override open func visit(_ node: SwitchCaseLabelSyntax) -> SyntaxVisitorContinueKind {
18731881
return visitAny(node._syntaxNode)
18741882
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
610610

611611
public init?<S: SyntaxProtocol>(_ node: S) {
612612
switch node.raw.kind {
613-
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .tupleType:
613+
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .suppressedType, .tupleType:
614614
self._syntaxNode = node._syntaxNode
615615
default:
616616
return nil
@@ -622,7 +622,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
622622
/// is undefined.
623623
internal init(_ data: SyntaxData) {
624624
switch data.raw.kind {
625-
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .tupleType:
625+
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .constrainedSugarType, .dictionaryType, .functionType, .implicitlyUnwrappedOptionalType, .memberTypeIdentifier, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packExpansionType, .packReferenceType, .simpleTypeIdentifier, .suppressedType, .tupleType:
626626
break
627627
default:
628628
preconditionFailure("Unable to create TypeSyntax from \(data.raw.kind)")
@@ -674,6 +674,7 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
674674
.node(PackExpansionTypeSyntax.self),
675675
.node(PackReferenceTypeSyntax.self),
676676
.node(SimpleTypeIdentifierSyntax.self),
677+
.node(SuppressedTypeSyntax.self),
677678
.node(TupleTypeSyntax.self)
678679
])
679680
}
@@ -910,6 +911,7 @@ extension Syntax {
910911
.node(SubscriptDeclSyntax.self),
911912
.node(SubscriptExprSyntax.self),
912913
.node(SuperRefExprSyntax.self),
914+
.node(SuppressedTypeSyntax.self),
913915
.node(SwitchCaseLabelSyntax.self),
914916
.node(SwitchCaseListSyntax.self),
915917
.node(SwitchCaseSyntax.self),

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public enum SyntaxEnum {
243243
case subscriptDecl(SubscriptDeclSyntax)
244244
case subscriptExpr(SubscriptExprSyntax)
245245
case superRefExpr(SuperRefExprSyntax)
246+
case suppressedType(SuppressedTypeSyntax)
246247
case switchCaseLabel(SwitchCaseLabelSyntax)
247248
case switchCaseList(SwitchCaseListSyntax)
248249
case switchCase(SwitchCaseSyntax)
@@ -746,6 +747,8 @@ public extension Syntax {
746747
return .subscriptExpr(SubscriptExprSyntax(self)!)
747748
case .superRefExpr:
748749
return .superRefExpr(SuperRefExprSyntax(self)!)
750+
case .suppressedType:
751+
return .suppressedType(SuppressedTypeSyntax(self)!)
749752
case .switchCaseLabel:
750753
return .switchCaseLabel(SwitchCaseLabelSyntax(self)!)
751754
case .switchCaseList:

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public enum SyntaxKind {
243243
case subscriptDecl
244244
case subscriptExpr
245245
case superRefExpr
246+
case suppressedType
246247
case switchCaseLabel
247248
case switchCaseList
248249
case switchCase
@@ -861,6 +862,8 @@ public enum SyntaxKind {
861862
return SubscriptExprSyntax.self
862863
case .superRefExpr:
863864
return SuperRefExprSyntax.self
865+
case .suppressedType:
866+
return SuppressedTypeSyntax.self
864867
case .switchCaseLabel:
865868
return SwitchCaseLabelSyntax.self
866869
case .switchCaseList:

0 commit comments

Comments
 (0)