Skip to content

Commit 3c45445

Browse files
authored
Merge pull request #2395 from rintaro/wildcardpattern-typeannotation
2 parents c4529c1 + 82c7c49 commit 3c45445

File tree

8 files changed

+68
-88
lines changed

8 files changed

+68
-88
lines changed

CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift

Lines changed: 7 additions & 11 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)])
226-
),
227-
Child(
228-
name: "typeAnnotation",
229-
kind: .node(kind: .typeAnnotation),
230-
documentation: "The type of the pattern.",
231-
isOptional: true
232-
),
228+
)
233229
]
234230
),
235231

Release Notes/510.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
- Issue: https://github.com/apple/swift-syntax/issues/2092
4141
- Pull Request: https://github.com/apple/swift-syntax/pull/2108
4242

43+
- `WildcardPatternSyntax.typeAnnotation`
44+
- Description: `typeAnnotation` on `WildcardPatternSyntax` was a mistake. Use `typeAnnotation` properties on the outer constructs instead. E.g. `PatternBindingListSyntax.typeAnnotation`
45+
- Pull Request: https://github.com/apple/swift-syntax/pull/2393
46+
4347
## API-Incompatible Changes
4448

4549
- `NoteMessage.fixItID` renamed to `noteID`

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,45 @@ public extension TypeEffectSpecifiersSyntax {
541541
}
542542
}
543543

544+
public extension WildcardPatternSyntax {
545+
@available(*, deprecated, message: "remove 'typeAnnotation'")
546+
init(
547+
leadingTrivia: Trivia? = nil,
548+
_ unexpectedBeforeWildcard: UnexpectedNodesSyntax? = nil,
549+
wildcard: TokenSyntax = .wildcardToken(),
550+
_ unexpectedBetweenWildcardAndTypeAnnotation: UnexpectedNodesSyntax? = nil,
551+
typeAnnotation: TypeAnnotationSyntax? = nil,
552+
_ unexpectedAfterTypeAnnotation: UnexpectedNodesSyntax? = nil,
553+
trailingTrivia: Trivia? = nil
554+
) {
555+
self.init(
556+
leadingTrivia: leadingTrivia,
557+
unexpectedBeforeWildcard,
558+
wildcard: wildcard,
559+
unexpectedAfterTypeAnnotation,
560+
trailingTrivia: trailingTrivia
561+
);
562+
}
563+
564+
@available(*, deprecated, message: "'unexpectedBetweenWildcardAndTypeAnnotation' was removed")
565+
var unexpectedBetweenWildcardAndTypeAnnotation: UnexpectedNodesSyntax? {
566+
get { nil }
567+
set {}
568+
}
569+
570+
@available(*, deprecated, message: "'typeAnnotation' was removed")
571+
var typeAnnotation: TypeAnnotationSyntax? {
572+
get { nil }
573+
set {}
574+
}
575+
576+
@available(*, deprecated, renamed: "unexpectedAfterWildcard")
577+
var unexpectedAfterTypeAnnotation: UnexpectedNodesSyntax? {
578+
get { unexpectedAfterWildcard }
579+
set { unexpectedAfterWildcard = newValue }
580+
}
581+
}
582+
544583
//==========================================================================//
545584
// IMPORTANT: If you are tempted to add a compatibility layer code here //
546585
// 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
@@ -2409,19 +2409,15 @@ public struct RawWildcardPatternSyntax: RawPatternSyntaxNodeProtocol {
24092409
public init(
24102410
_ unexpectedBeforeWildcard: RawUnexpectedNodesSyntax? = nil,
24112411
wildcard: RawTokenSyntax,
2412-
_ unexpectedBetweenWildcardAndTypeAnnotation: RawUnexpectedNodesSyntax? = nil,
2413-
typeAnnotation: RawTypeAnnotationSyntax?,
2414-
_ unexpectedAfterTypeAnnotation: RawUnexpectedNodesSyntax? = nil,
2412+
_ unexpectedAfterWildcard: RawUnexpectedNodesSyntax? = nil,
24152413
arena: __shared SyntaxArena
24162414
) {
24172415
let raw = RawSyntax.makeLayout(
2418-
kind: .wildcardPattern, uninitializedCount: 5, arena: arena) { layout in
2416+
kind: .wildcardPattern, uninitializedCount: 3, arena: arena) { layout in
24192417
layout.initialize(repeating: nil)
24202418
layout[0] = unexpectedBeforeWildcard?.raw
24212419
layout[1] = wildcard.raw
2422-
layout[2] = unexpectedBetweenWildcardAndTypeAnnotation?.raw
2423-
layout[3] = typeAnnotation?.raw
2424-
layout[4] = unexpectedAfterTypeAnnotation?.raw
2420+
layout[2] = unexpectedAfterWildcard?.raw
24252421
}
24262422
self.init(unchecked: raw)
24272423
}
@@ -2434,17 +2430,9 @@ public struct RawWildcardPatternSyntax: RawPatternSyntaxNodeProtocol {
24342430
layoutView.children[1].map(RawTokenSyntax.init(raw:))!
24352431
}
24362432

2437-
public var unexpectedBetweenWildcardAndTypeAnnotation: RawUnexpectedNodesSyntax? {
2433+
public var unexpectedAfterWildcard: RawUnexpectedNodesSyntax? {
24382434
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
24392435
}
2440-
2441-
public var typeAnnotation: RawTypeAnnotationSyntax? {
2442-
layoutView.children[3].map(RawTypeAnnotationSyntax.init(raw:))
2443-
}
2444-
2445-
public var unexpectedAfterTypeAnnotation: RawUnexpectedNodesSyntax? {
2446-
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
2447-
}
24482436
}
24492437

24502438
@_spi(RawSyntax)

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,12 +2720,10 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
27202720
assertNoError(kind, 5, verify(layout[5], as: RawCodeBlockSyntax.self))
27212721
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
27222722
case .wildcardPattern:
2723-
assert(layout.count == 5)
2723+
assert(layout.count == 3)
27242724
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
27252725
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.wildcard)]))
27262726
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
2727-
assertNoError(kind, 3, verify(layout[3], as: RawTypeAnnotationSyntax?.self))
2728-
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
27292727
case .yieldStmt:
27302728
assert(layout.count == 5)
27312729
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)