Skip to content

Commit ca2df7d

Browse files
committed
Remove WildcardPattern.typeAnnotation
Type annotation has never been a part of `wildcard-pattern`.
1 parent c247510 commit ca2df7d

File tree

7 files changed

+48
-87
lines changed

7 files changed

+48
-87
lines changed

CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public let PATTERN_NODES: [Node] = [
138138
### Examples
139139
140140
``TuplePatternSyntax`` can be used in more complex variable declarations.
141-
For example `(x, y)` in the exmaple:
141+
For example `(x, y)` in the example:
142142
143143
```swift
144144
let (x, y) = (1, 2)
@@ -212,24 +212,20 @@ public let PATTERN_NODES: [Node] = [
212212
213213
### Examples
214214
215-
``TuplePatternSyntax`` can be used in a simple variable declarations.
216-
For example `_` in the exmaple:
215+
``WildcardPattern`` matches and ignores any value.
216+
For example `_` in the example:
217217
218218
```swift
219-
let _: Int = (1, 2)
219+
for _ in 1...3 {
220+
// ...
221+
}
220222
```
221223
""",
222224
children: [
223225
Child(
224226
name: "wildcard",
225227
kind: .token(choices: [.token(.wildcard)])
226228
),
227-
Child(
228-
name: "typeAnnotation",
229-
kind: .node(kind: .typeAnnotation),
230-
documentation: "The type of the pattern.",
231-
isOptional: true
232-
),
233229
]
234230
),
235231

Sources/SwiftParser/Patterns.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ extension Parser {
6464
return RawPatternSyntax(
6565
RawWildcardPatternSyntax(
6666
wildcard: wildcard,
67-
typeAnnotation: nil,
6867
arena: self.arena
6968
)
7069
)

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,30 @@ public extension TypeEffectSpecifiersSyntax {
509509
}
510510
}
511511

512+
public extension WildcardPatternSyntax {
513+
@available(*, deprecated, message: "remove 'typeAnnotation'")
514+
init(
515+
leadingTrivia: Trivia? = nil,
516+
wildcard: TokenSyntax = .wildcardToken(),
517+
typeAnnotation: TypeAnnotationSyntax? = nil,
518+
trailingTrivia: Trivia? = nil
519+
) {
520+
self.init(
521+
leadingTrivia: leadingTrivia,
522+
nil,
523+
wildcard: wildcard,
524+
nil,
525+
trailingTrivia: trailingTrivia
526+
);
527+
}
528+
529+
@available(*, deprecated, message: "'typeAnnotation' was removed")
530+
var typeAnnotation: TypeAnnotationSyntax? {
531+
get { nil }
532+
set {}
533+
}
534+
}
535+
512536
//==========================================================================//
513537
// IMPORTANT: If you are tempted to add a compatibility layer code here //
514538
// please insert it in alphabetical order above //

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,12 +3423,8 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
34233423
return "unexpectedBeforeWildcard"
34243424
case \WildcardPatternSyntax.wildcard:
34253425
return "wildcard"
3426-
case \WildcardPatternSyntax.unexpectedBetweenWildcardAndTypeAnnotation:
3427-
return "unexpectedBetweenWildcardAndTypeAnnotation"
3428-
case \WildcardPatternSyntax.typeAnnotation:
3429-
return "typeAnnotation"
3430-
case \WildcardPatternSyntax.unexpectedAfterTypeAnnotation:
3431-
return "unexpectedAfterTypeAnnotation"
3426+
case \WildcardPatternSyntax.unexpectedAfterWildcard:
3427+
return "unexpectedAfterWildcard"
34323428
case \YieldStmtSyntax.unexpectedBeforeYieldKeyword:
34333429
return "unexpectedBeforeYieldKeyword"
34343430
case \YieldStmtSyntax.yieldKeyword:

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesTUVWXYZ.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,19 +2395,15 @@ public struct RawWildcardPatternSyntax: RawPatternSyntaxNodeProtocol {
23952395
public init(
23962396
_ unexpectedBeforeWildcard: RawUnexpectedNodesSyntax? = nil,
23972397
wildcard: RawTokenSyntax,
2398-
_ unexpectedBetweenWildcardAndTypeAnnotation: RawUnexpectedNodesSyntax? = nil,
2399-
typeAnnotation: RawTypeAnnotationSyntax?,
2400-
_ unexpectedAfterTypeAnnotation: RawUnexpectedNodesSyntax? = nil,
2398+
_ unexpectedAfterWildcard: RawUnexpectedNodesSyntax? = nil,
24012399
arena: __shared SyntaxArena
24022400
) {
24032401
let raw = RawSyntax.makeLayout(
2404-
kind: .wildcardPattern, uninitializedCount: 5, arena: arena) { layout in
2402+
kind: .wildcardPattern, uninitializedCount: 3, arena: arena) { layout in
24052403
layout.initialize(repeating: nil)
24062404
layout[0] = unexpectedBeforeWildcard?.raw
24072405
layout[1] = wildcard.raw
2408-
layout[2] = unexpectedBetweenWildcardAndTypeAnnotation?.raw
2409-
layout[3] = typeAnnotation?.raw
2410-
layout[4] = unexpectedAfterTypeAnnotation?.raw
2406+
layout[2] = unexpectedAfterWildcard?.raw
24112407
}
24122408
self.init(unchecked: raw)
24132409
}
@@ -2420,17 +2416,9 @@ public struct RawWildcardPatternSyntax: RawPatternSyntaxNodeProtocol {
24202416
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
24212417
}
24222418

2423-
public var unexpectedBetweenWildcardAndTypeAnnotation: RawUnexpectedNodesSyntax? {
2419+
public var unexpectedAfterWildcard: RawUnexpectedNodesSyntax? {
24242420
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
24252421
}
2426-
2427-
public var typeAnnotation: RawTypeAnnotationSyntax? {
2428-
layoutView.children[3].map(RawTypeAnnotationSyntax.init(raw:))
2429-
}
2430-
2431-
public var unexpectedAfterTypeAnnotation: RawUnexpectedNodesSyntax? {
2432-
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
2433-
}
24342422
}
24352423

24362424
@_spi(RawSyntax)

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,12 +2718,10 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
27182718
assertNoError(kind, 5, verify(layout[5], as: RawCodeBlockSyntax.self))
27192719
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
27202720
case .wildcardPattern:
2721-
assert(layout.count == 5)
2721+
assert(layout.count == 3)
27222722
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
27232723
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.wildcard)]))
27242724
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
2725-
assertNoError(kind, 3, verify(layout[3], as: RawTypeAnnotationSyntax?.self))
2726-
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
27272725
case .yieldStmt:
27282726
assert(layout.count == 5)
27292727
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ public struct TuplePatternElementSyntax: SyntaxProtocol, SyntaxHashable, _LeafSy
12041204
/// ### Examples
12051205
///
12061206
/// ``TuplePatternSyntax`` can be used in more complex variable declarations.
1207-
/// For example `(x, y)` in the exmaple:
1207+
/// For example `(x, y)` in the example:
12081208
///
12091209
/// ```swift
12101210
/// let (x, y) = (1, 2)
@@ -2159,7 +2159,6 @@ public struct TypeAliasDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDecl
21592159
/// - ``MatchingPatternConditionSyntax``.``MatchingPatternConditionSyntax/typeAnnotation``
21602160
/// - ``OptionalBindingConditionSyntax``.``OptionalBindingConditionSyntax/typeAnnotation``
21612161
/// - ``PatternBindingSyntax``.``PatternBindingSyntax/typeAnnotation``
2162-
/// - ``WildcardPatternSyntax``.``WildcardPatternSyntax/typeAnnotation``
21632162
public struct TypeAnnotationSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol {
21642163
public let _syntaxNode: Syntax
21652164

@@ -4242,17 +4241,18 @@ public struct WhileStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSynt
42424241
///
42434242
/// ### Examples
42444243
///
4245-
/// ``TuplePatternSyntax`` can be used in a simple variable declarations.
4246-
/// For example `_` in the exmaple:
4244+
/// ``WildcardPattern`` matches and ignores any value.
4245+
/// For example `_` in the example:
42474246
///
42484247
/// ```swift
4249-
/// let _: Int = (1, 2)
4248+
/// for _ in 1...3 {
4249+
/// // ...
4250+
/// }
42504251
/// ```
42514252
///
42524253
/// ### Children
42534254
///
42544255
/// - `wildcard`: `_`
4255-
/// - `typeAnnotation`: ``TypeAnnotationSyntax``?
42564256
public struct WildcardPatternSyntax: PatternSyntaxProtocol, SyntaxHashable, _LeafPatternSyntaxNodeProtocol {
42574257
public let _syntaxNode: Syntax
42584258

@@ -4265,34 +4265,19 @@ public struct WildcardPatternSyntax: PatternSyntaxProtocol, SyntaxHashable, _Lea
42654265

42664266
/// - Parameters:
42674267
/// - leadingTrivia: Trivia to be prepended to the leading trivia of the node’s first token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
4268-
/// - typeAnnotation: The type of the pattern.
42694268
/// - trailingTrivia: Trivia to be appended to the trailing trivia of the node’s last token. If the node is empty, there is no token to attach the trivia to and the parameter is ignored.
42704269
public init(
42714270
leadingTrivia: Trivia? = nil,
42724271
_ unexpectedBeforeWildcard: UnexpectedNodesSyntax? = nil,
42734272
wildcard: TokenSyntax = .wildcardToken(),
4274-
_ unexpectedBetweenWildcardAndTypeAnnotation: UnexpectedNodesSyntax? = nil,
4275-
typeAnnotation: TypeAnnotationSyntax? = nil,
4276-
_ unexpectedAfterTypeAnnotation: UnexpectedNodesSyntax? = nil,
4273+
_ unexpectedAfterWildcard: UnexpectedNodesSyntax? = nil,
42774274
trailingTrivia: Trivia? = nil
42784275

42794276
) {
42804277
// Extend the lifetime of all parameters so their arenas don't get destroyed
42814278
// before they can be added as children of the new arena.
4282-
self = withExtendedLifetime((SyntaxArena(), (
4283-
unexpectedBeforeWildcard,
4284-
wildcard,
4285-
unexpectedBetweenWildcardAndTypeAnnotation,
4286-
typeAnnotation,
4287-
unexpectedAfterTypeAnnotation
4288-
))) { (arena, _) in
4289-
let layout: [RawSyntax?] = [
4290-
unexpectedBeforeWildcard?.raw,
4291-
wildcard.raw,
4292-
unexpectedBetweenWildcardAndTypeAnnotation?.raw,
4293-
typeAnnotation?.raw,
4294-
unexpectedAfterTypeAnnotation?.raw
4295-
]
4279+
self = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeWildcard, wildcard, unexpectedAfterWildcard))) { (arena, _) in
4280+
let layout: [RawSyntax?] = [unexpectedBeforeWildcard?.raw, wildcard.raw, unexpectedAfterWildcard?.raw]
42964281
let raw = RawSyntax.makeLayout(
42974282
kind: SyntaxKind.wildcardPattern,
42984283
from: layout,
@@ -4326,7 +4311,7 @@ public struct WildcardPatternSyntax: PatternSyntaxProtocol, SyntaxHashable, _Lea
43264311
}
43274312
}
43284313

4329-
public var unexpectedBetweenWildcardAndTypeAnnotation: UnexpectedNodesSyntax? {
4314+
public var unexpectedAfterWildcard: UnexpectedNodesSyntax? {
43304315
get {
43314316
return Syntax(self).child(at: 2)?.cast(UnexpectedNodesSyntax.self)
43324317
}
@@ -4335,33 +4320,8 @@ public struct WildcardPatternSyntax: PatternSyntaxProtocol, SyntaxHashable, _Lea
43354320
}
43364321
}
43374322

4338-
/// The type of the pattern.
4339-
public var typeAnnotation: TypeAnnotationSyntax? {
4340-
get {
4341-
return Syntax(self).child(at: 3)?.cast(TypeAnnotationSyntax.self)
4342-
}
4343-
set(value) {
4344-
self = Syntax(self).replacingChild(at: 3, with: Syntax(value), arena: SyntaxArena()).cast(WildcardPatternSyntax.self)
4345-
}
4346-
}
4347-
4348-
public var unexpectedAfterTypeAnnotation: UnexpectedNodesSyntax? {
4349-
get {
4350-
return Syntax(self).child(at: 4)?.cast(UnexpectedNodesSyntax.self)
4351-
}
4352-
set(value) {
4353-
self = Syntax(self).replacingChild(at: 4, with: Syntax(value), arena: SyntaxArena()).cast(WildcardPatternSyntax.self)
4354-
}
4355-
}
4356-
43574323
public static var structure: SyntaxNodeStructure {
4358-
return .layout([
4359-
\Self.unexpectedBeforeWildcard,
4360-
\Self.wildcard,
4361-
\Self.unexpectedBetweenWildcardAndTypeAnnotation,
4362-
\Self.typeAnnotation,
4363-
\Self.unexpectedAfterTypeAnnotation
4364-
])
4324+
return .layout([\Self.unexpectedBeforeWildcard, \Self.wildcard, \Self.unexpectedAfterWildcard])
43654325
}
43664326
}
43674327

0 commit comments

Comments
 (0)