Skip to content

Replace throwsSpecifier/thrownTypeClause with a unified throwsClause #2379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 2, 2023
Merged
63 changes: 25 additions & 38 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,36 @@ public let COMMON_NODES: [Node] = [
),

Node(
kind: .thrownTypeClause,
kind: .throwsClause,
base: .syntax,
nameForDiagnostics: "thrown type clause",
documentation: "The specific error type that a function can throw.",
traits: [
"Parenthesized"
],
nameForDiagnostics: "throws clause",
children: [
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
documentation: "The `throws` keyword."
),
Child(
name: "leftParen",
kind: .token(choices: [.token(.leftParen)]),
documentation: "The '(' to open the thrown type clause."
experimentalFeature: .typedThrows,
documentation: "The '(' to open the thrown error type specification.",
isOptional: true
),
Child(
name: "type",
kind: .node(kind: .type),
experimentalFeature: .typedThrows,
nameForDiagnostics: "thrown type",
documentation: "The thrown error type."
documentation: "The thrown error type.",
isOptional: true
),
Child(
name: "rightParen",
kind: .token(choices: [.token(.rightParen)]),
documentation: "The ')' to closure the thrown type clause."
experimentalFeature: .typedThrows,
documentation: "The ')' to close the thrown error type specification.",
isOptional: true
),
]
),
Expand All @@ -123,16 +130,9 @@ public let COMMON_NODES: [Node] = [
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(.throws)]),
documentation: "The `throws` keyword.",
isOptional: true
),
Child(
name: "thrownError",
kind: .node(kind: .thrownTypeClause),
experimentalFeature: .typedThrows,
documentation: "The specific error type thrown by this accessor.",
name: "throwsClause",
kind: .node(kind: .throwsClause),
documentation: "The clause specifying thrown errors",
isOptional: true
),
]
Expand All @@ -153,16 +153,9 @@ public let COMMON_NODES: [Node] = [
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]),
documentation: "The `throws` or `rethrows` keyword.",
isOptional: true
),
Child(
name: "thrownError",
kind: .node(kind: .thrownTypeClause),
experimentalFeature: .typedThrows,
documentation: "The specific error type thrown by this function.",
name: "throwsClause",
kind: .node(kind: .throwsClause),
documentation: "The clause specifying thrown errors",
isOptional: true
),
]
Expand Down Expand Up @@ -363,15 +356,9 @@ public let COMMON_NODES: [Node] = [
isOptional: true
),
Child(
name: "throwsSpecifier",
kind: .token(choices: [.keyword(.throws)]),
isOptional: true
),
Child(
name: "thrownError",
kind: .node(kind: .thrownTypeClause),
experimentalFeature: .typedThrows,
documentation: "The specific error type thrown by this function type.",
name: "throwsClause",
kind: .node(kind: .throwsClause),
documentation: "The clause specifying thrown errors",
isOptional: true
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
case switchExpr
case ternaryExpr
case thenStmt
case thrownTypeClause
case throwsClause
case throwStmt
case tryExpr
case tupleExpr
Expand Down
14 changes: 3 additions & 11 deletions CodeGeneration/Sources/SyntaxSupport/Traits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ public let TRAITS: [Trait] = [
children: [
Child(name: "unexpectedBeforeAsyncSpecifier", kind: .node(kind: .unexpectedNodes), isOptional: true),
Child(name: "asyncSpecifier", kind: .token(choices: [.keyword(.async), .keyword(.reasync)]), isOptional: true),
Child(name: "unexpectedBetweenAsyncSpecifierAndThrowsSpecifier", kind: .node(kind: .unexpectedNodes), isOptional: true),
Child(name: "throwsSpecifier", kind: .token(choices: [.keyword(.throws), .keyword(.rethrows)]), isOptional: true),
Child(name: "unexpectedBetweenThrowsSpecifierAndThrownError", kind: .node(kind: .unexpectedNodes), isOptional: true),
Child(
name: "thrownError",
kind: .node(kind: .thrownTypeClause),
experimentalFeature: .typedThrows,
documentation: "The specific thrown error type.",
isOptional: true
),
Child(name: "unexpectedAfterThrownError", kind: .node(kind: .unexpectedNodes), isOptional: true),
Child(name: "unexpectedBetweenAsyncSpecifierAndThrowsClause", kind: .node(kind: .unexpectedNodes), isOptional: true),
Child(name: "throwsClause", kind: .node(kind: .throwsClause), isOptional: true),
Child(name: "unexpectedAfterThrowsClause", kind: .node(kind: .unexpectedNodes), isOptional: true),
]
),
Trait(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ class ValidateSyntaxNodes: XCTestCase {
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
),
ValidationFailure(
node: .accessorEffectSpecifiers,
message: "child 'throwsSpecifier' has a single keyword as its only token choice and should thus be named 'throwsKeyword'"
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
),
ValidationFailure(
node: .deinitializerEffectSpecifiers,
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
Expand All @@ -240,11 +235,6 @@ class ValidateSyntaxNodes: XCTestCase {
message: "child 'asyncSpecifier' has a single keyword as its only token choice and should thus be named 'asyncKeyword'"
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
),
ValidationFailure(
node: .typeEffectSpecifiers,
message: "child 'throwsSpecifier' has a single keyword as its only token choice and should thus be named 'throwsKeyword'"
// To be consistent with AsyncSpecifier properties that can be both 'async' and 'reasync'
),

// MARK: Two tokens with same kind in a node
// If there are two tokens of the same kind in a node, we can't follow the naming rule without conflict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public struct AddAsyncMacro: PeerMacro {
funcDecl.signature.effectSpecifiers = FunctionEffectSpecifiersSyntax(
leadingTrivia: .space,
asyncSpecifier: .keyword(.async),
throwsSpecifier: isResultReturn ? .keyword(.throws) : nil
throwsClause: isResultReturn ? ThrowsClauseSyntax(throwsSpecifier: .keyword(.throws)) : nil
)

// add result type
Expand Down
4 changes: 4 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
- Description: `CodeBlockSyntax` is now `SyntaxParseable`, so it can be used with string interpolations.
- Pull Request: https://github.com/apple/swift-syntax/pull/2361

- `ThrowsClause`
- 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.
- Pull Request: https://github.com/apple/swift-syntax/pull/2379

## API Behavior Changes

## Deprecations
Expand Down
Loading