Skip to content

Commit 201e0e3

Browse files
authored
Merge pull request #2393 from ahoppen/ahoppen/throws-clause-review-comments
Address review comments for API compatibility of `ThrowsClauseSyntax`
2 parents c247510 + 5b04406 commit 201e0e3

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Release Notes/511.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
- The new classification case covers the first names of parameters in function-like declarations and the label of arguments in function-like calls.
8585
- Pull request: https://github.com/apple/swift-syntax/pull/2375
8686
- Migration steps: In exhaustive switches over `SyntaxClassification`, cover the new case.
87+
88+
- `SyntaxEnum` and `SyntaxKind` gained new cases: `throwsClause`
89+
- The new cases cover the newly introduced `ThrowsClauseSyntax`
90+
- Pull request: https://github.com/apple/swift-syntax/pull/2379
91+
- Migration steps: In exhaustive switches over `SyntaxEnum` and `SyntaxKind`, cover the new case.
92+
8793

8894
## Template
8995

Sources/SwiftParser/Specifiers.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ extension TokenConsumer {
584584
extension Parser {
585585
/// Parse a throws clause after we've already parsed the 'throws' keyword to introduce it.
586586
mutating func parseThrowsClause(after throwsKeyword: RawTokenSyntax) -> RawThrowsClauseSyntax {
587-
guard self.at(.leftParen) && experimentalFeatures.contains(.typedThrows) else {
587+
guard experimentalFeatures.contains(.typedThrows), let leftParen = self.consume(if: .leftParen) else {
588588
return RawThrowsClauseSyntax(
589589
throwsSpecifier: throwsKeyword,
590590
leftParen: nil,
@@ -594,12 +594,10 @@ extension Parser {
594594
)
595595
}
596596

597-
let (unexpectedBetweenThrowsSpecifierAndLeftParen, leftParen) = self.expect(.leftParen)
598597
let type = self.parseType()
599598
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
600599
return RawThrowsClauseSyntax(
601600
throwsSpecifier: throwsKeyword,
602-
unexpectedBetweenThrowsSpecifierAndLeftParen,
603601
leftParen: leftParen,
604602
type: type,
605603
unexpectedBeforeRightParen,

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@
1414
// All users of the declarations in this file should transition away from them ASAP.
1515

1616
public extension AccessorEffectSpecifiersSyntax {
17+
@_disfavoredOverload
1718
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
1819
init(
1920
leadingTrivia: Trivia? = nil,
21+
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
2022
asyncSpecifier: TokenSyntax? = nil,
23+
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
2124
throwsSpecifier: TokenSyntax? = nil,
25+
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
2226
trailingTrivia: Trivia? = nil
2327
) {
2428
self.init(
2529
leadingTrivia: leadingTrivia,
30+
unexpectedBeforeAsyncSpecifier,
2631
asyncSpecifier: asyncSpecifier,
32+
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
2733
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
34+
unexpectedAfterThrowsSpecifier,
2835
trailingTrivia: trailingTrivia
2936
)
3037
}
@@ -68,6 +75,12 @@ public extension DeclGroupSyntax {
6875
}
6976

7077
public extension EffectSpecifiersSyntax {
78+
@available(*, deprecated, renamed: "unexpectedBetweenAsyncSpecifierAndThrowsClause")
79+
var unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? {
80+
get { unexpectedBetweenAsyncSpecifierAndThrowsClause }
81+
set { unexpectedBetweenAsyncSpecifierAndThrowsClause = newValue }
82+
}
83+
7184
@available(*, deprecated, message: "use throwsClause.throwsSpecifier")
7285
var throwsSpecifier: TokenSyntax? {
7386
get { throwsClause?.throwsSpecifier }
@@ -85,20 +98,33 @@ public extension EffectSpecifiersSyntax {
8598
}
8699
}
87100
}
101+
102+
@available(*, deprecated, renamed: "unexpectedAfterThrowsClause")
103+
var unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? {
104+
get { unexpectedAfterThrowsClause }
105+
set { unexpectedAfterThrowsClause = newValue }
106+
}
88107
}
89108

90109
public extension FunctionEffectSpecifiersSyntax {
110+
@_disfavoredOverload
91111
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
92112
init(
93113
leadingTrivia: Trivia? = nil,
114+
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
94115
asyncSpecifier: TokenSyntax? = nil,
116+
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
95117
throwsSpecifier: TokenSyntax? = nil,
118+
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
96119
trailingTrivia: Trivia? = nil
97120
) {
98121
self.init(
99122
leadingTrivia: leadingTrivia,
123+
unexpectedBeforeAsyncSpecifier,
100124
asyncSpecifier: asyncSpecifier,
125+
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
101126
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
127+
unexpectedAfterThrowsSpecifier,
102128
trailingTrivia: trailingTrivia
103129
)
104130
}
@@ -496,14 +522,20 @@ public extension TypeEffectSpecifiersSyntax {
496522
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
497523
init(
498524
leadingTrivia: Trivia? = nil,
525+
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
499526
asyncSpecifier: TokenSyntax? = nil,
527+
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
500528
throwsSpecifier: TokenSyntax? = nil,
529+
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
501530
trailingTrivia: Trivia? = nil
502531
) {
503532
self.init(
504533
leadingTrivia: leadingTrivia,
534+
unexpectedBeforeAsyncSpecifier,
505535
asyncSpecifier: asyncSpecifier,
536+
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
506537
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
538+
unexpectedAfterThrowsSpecifier,
507539
trailingTrivia: trailingTrivia
508540
)
509541
}

0 commit comments

Comments
 (0)