Skip to content

Commit 5cec9bd

Browse files
authored
Merge pull request #2379 from DougGregor/throws-clause
Replace throwsSpecifier/thrownTypeClause with a unified throwsClause
2 parents 6e708c4 + ebd8e2e commit 5cec9bd

33 files changed

+489
-577
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,36 @@ public let COMMON_NODES: [Node] = [
8181
),
8282

8383
Node(
84-
kind: .thrownTypeClause,
84+
kind: .throwsClause,
8585
base: .syntax,
86-
nameForDiagnostics: "thrown type clause",
87-
documentation: "The specific error type that a function can throw.",
88-
traits: [
89-
"Parenthesized"
90-
],
86+
nameForDiagnostics: "throws clause",
9187
children: [
88+
Child(
89+
name: "throwsSpecifier",
90+
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
91+
documentation: "The `throws` keyword."
92+
),
9293
Child(
9394
name: "leftParen",
9495
kind: .token(choices: [.token(.leftParen)]),
95-
documentation: "The '(' to open the thrown type clause."
96+
experimentalFeature: .typedThrows,
97+
documentation: "The '(' to open the thrown error type specification.",
98+
isOptional: true
9699
),
97100
Child(
98101
name: "type",
99102
kind: .node(kind: .type),
103+
experimentalFeature: .typedThrows,
100104
nameForDiagnostics: "thrown type",
101-
documentation: "The thrown error type."
105+
documentation: "The thrown error type.",
106+
isOptional: true
102107
),
103108
Child(
104109
name: "rightParen",
105110
kind: .token(choices: [.token(.rightParen)]),
106-
documentation: "The ')' to closure the thrown type clause."
111+
experimentalFeature: .typedThrows,
112+
documentation: "The ')' to close the thrown error type specification.",
113+
isOptional: true
107114
),
108115
]
109116
),
@@ -123,16 +130,9 @@ public let COMMON_NODES: [Node] = [
123130
isOptional: true
124131
),
125132
Child(
126-
name: "throwsSpecifier",
127-
kind: .token(choices: [.keyword(.throws)]),
128-
documentation: "The `throws` keyword.",
129-
isOptional: true
130-
),
131-
Child(
132-
name: "thrownError",
133-
kind: .node(kind: .thrownTypeClause),
134-
experimentalFeature: .typedThrows,
135-
documentation: "The specific error type thrown by this accessor.",
133+
name: "throwsClause",
134+
kind: .node(kind: .throwsClause),
135+
documentation: "The clause specifying thrown errors",
136136
isOptional: true
137137
),
138138
]
@@ -153,16 +153,9 @@ public let COMMON_NODES: [Node] = [
153153
isOptional: true
154154
),
155155
Child(
156-
name: "throwsSpecifier",
157-
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
158-
documentation: "The `throws` or `rethrows` keyword.",
159-
isOptional: true
160-
),
161-
Child(
162-
name: "thrownError",
163-
kind: .node(kind: .thrownTypeClause),
164-
experimentalFeature: .typedThrows,
165-
documentation: "The specific error type thrown by this function.",
156+
name: "throwsClause",
157+
kind: .node(kind: .throwsClause),
158+
documentation: "The clause specifying thrown errors",
166159
isOptional: true
167160
),
168161
]
@@ -363,15 +356,9 @@ public let COMMON_NODES: [Node] = [
363356
isOptional: true
364357
),
365358
Child(
366-
name: "throwsSpecifier",
367-
kind: .token(choices: [.keyword(.throws)]),
368-
isOptional: true
369-
),
370-
Child(
371-
name: "thrownError",
372-
kind: .node(kind: .thrownTypeClause),
373-
experimentalFeature: .typedThrows,
374-
documentation: "The specific error type thrown by this function type.",
359+
name: "throwsClause",
360+
kind: .node(kind: .throwsClause),
361+
documentation: "The clause specifying thrown errors",
375362
isOptional: true
376363
),
377364
]

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
269269
case switchExpr
270270
case ternaryExpr
271271
case thenStmt
272-
case thrownTypeClause
272+
case throwsClause
273273
case throwStmt
274274
case tryExpr
275275
case tupleExpr

CodeGeneration/Sources/SyntaxSupport/Traits.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,9 @@ public let TRAITS: [Trait] = [
6262
children: [
6363
Child(name: "unexpectedBeforeAsyncSpecifier", kind: .node(kind: .unexpectedNodes), isOptional: true),
6464
Child(name: "asyncSpecifier", kind: .token(choices: [.keyword(.async), .keyword(.reasync)]), isOptional: true),
65-
Child(name: "unexpectedBetweenAsyncSpecifierAndThrowsSpecifier", kind: .node(kind: .unexpectedNodes), isOptional: true),
66-
Child(name: "throwsSpecifier", kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]), isOptional: true),
67-
Child(name: "unexpectedBetweenThrowsSpecifierAndThrownError", kind: .node(kind: .unexpectedNodes), isOptional: true),
68-
Child(
69-
name: "thrownError",
70-
kind: .node(kind: .thrownTypeClause),
71-
experimentalFeature: .typedThrows,
72-
documentation: "The specific thrown error type.",
73-
isOptional: true
74-
),
75-
Child(name: "unexpectedAfterThrownError", kind: .node(kind: .unexpectedNodes), isOptional: true),
65+
Child(name: "unexpectedBetweenAsyncSpecifierAndThrowsClause", kind: .node(kind: .unexpectedNodes), isOptional: true),
66+
Child(name: "throwsClause", kind: .node(kind: .throwsClause), isOptional: true),
67+
Child(name: "unexpectedAfterThrowsClause", kind: .node(kind: .unexpectedNodes), isOptional: true),
7668
]
7769
),
7870
Trait(

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ class ValidateSyntaxNodes: XCTestCase {
225225
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
226226
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
227227
),
228-
ValidationFailure(
229-
node: .accessorEffectSpecifiers,
230-
message: "child 'throwsSpecifier' has a single keyword as its only token choice and should thus be named 'throwsKeyword'"
231-
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
232-
),
233228
ValidationFailure(
234229
node: .deinitializerEffectSpecifiers,
235230
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
@@ -240,11 +235,6 @@ class ValidateSyntaxNodes: XCTestCase {
240235
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
241236
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
242237
),
243-
ValidationFailure(
244-
node: .typeEffectSpecifiers,
245-
message: "child 'throwsSpecifier' has a single keyword as its only token choice and should thus be named 'throwsKeyword'"
246-
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
247-
),
248238

249239
// MARK: Two tokens with same kind in a node
250240
// If there are two tokens of the same kind in a node, we can't follow the naming rule without conflict

Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public struct AddAsyncMacro: PeerMacro {
127127
funcDecl.signature.effectSpecifiers = FunctionEffectSpecifiersSyntax(
128128
leadingTrivia: .space,
129129
asyncSpecifier: .keyword(.async),
130-
throwsSpecifier: isResultReturn ? .keyword(.throws) : nil
130+
throwsClause: isResultReturn ? ThrowsClauseSyntax(throwsSpecifier: .keyword(.throws)) : nil
131131
)
132132

133133
// add result type

Release Notes/511.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
- Description: `CodeBlockSyntax` is now `SyntaxParseable`, so it can be used with string interpolations.
2929
- Pull Request: https://github.com/apple/swift-syntax/pull/2361
3030

31+
- `ThrowsClause`
32+
- Description: The `throwsSpecifier` for the effects nodes (`AccessorEffectSpecifiers`, `FunctionEffectSpecifiers`, `TypeEffectSpecifiers`, `EffectSpecifiers`) has been replaced with `throwsClause`, which captures both the throws specifier and the (optional) thrown error type, as introduced by SE-0413.
33+
- Pull Request: https://github.com/apple/swift-syntax/pull/2379
34+
3135
## API Behavior Changes
3236

3337
## Deprecations

0 commit comments

Comments
 (0)