Skip to content

Commit 7131e3b

Browse files
authored
Merge pull request #2412 from DougGregor/se-0413-typed-throws-accepted
[SE-0413] Typed throws: enable by default
2 parents e14af92 + 273178f commit 7131e3b

File tree

11 files changed

+39
-88
lines changed

11 files changed

+39
-88
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,19 @@ public let COMMON_NODES: [Node] = [
9393
Child(
9494
name: "leftParen",
9595
kind: .token(choices: [.token(.leftParen)]),
96-
experimentalFeature: .typedThrows,
9796
documentation: "The '(' to open the thrown error type specification.",
9897
isOptional: true
9998
),
10099
Child(
101100
name: "type",
102101
kind: .node(kind: .type),
103-
experimentalFeature: .typedThrows,
104102
nameForDiagnostics: "thrown type",
105103
documentation: "The thrown error type.",
106104
isOptional: true
107105
),
108106
Child(
109107
name: "rightParen",
110108
kind: .token(choices: [.token(.rightParen)]),
111-
experimentalFeature: .typedThrows,
112109
documentation: "The ')' to close the thrown error type specification.",
113110
isOptional: true
114111
),

CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import SwiftSyntax
1515
public enum ExperimentalFeature: String, CaseIterable {
1616
case referenceBindings
1717
case thenStatements
18-
case typedThrows
1918
case doExpressions
2019
case nonescapableTypes
2120
case transferringArgsAndResults
@@ -27,8 +26,6 @@ public enum ExperimentalFeature: String, CaseIterable {
2726
return "reference bindings"
2827
case .thenStatements:
2928
return "'then' statements"
30-
case .typedThrows:
31-
return "typed throws"
3229
case .doExpressions:
3330
return "'do' expressions"
3431
case .nonescapableTypes:

CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public let STMT_NODES: [Node] = [
219219
Child(
220220
name: "throwsClause",
221221
kind: .node(kind: .throwsClause),
222-
experimentalFeature: .typedThrows,
223222
documentation: "The clause specifying the type of errors thrown from the 'do' block.",
224223
isOptional: true
225224
),

Sources/SwiftParser/Specifiers.swift

Lines changed: 1 addition & 1 deletion
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 experimentalFeatures.contains(.typedThrows), let leftParen = self.consume(if: .leftParen) else {
587+
guard let leftParen = self.consume(if: .leftParen) else {
588588
return RawThrowsClauseSyntax(
589589
throwsSpecifier: throwsKeyword,
590590
leftParen: nil,

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ extension Parser.ExperimentalFeatures {
3030
/// Whether to enable the parsing of 'then' statements.
3131
public static let thenStatements = Self (rawValue: 1 << 1)
3232

33-
/// Whether to enable the parsing of typed throws.
34-
public static let typedThrows = Self (rawValue: 1 << 2)
35-
3633
/// Whether to enable the parsing of 'do' expressions.
37-
public static let doExpressions = Self (rawValue: 1 << 3)
34+
public static let doExpressions = Self (rawValue: 1 << 2)
3835

3936
/// Whether to enable the parsing of NonEscableTypes.
40-
public static let nonescapableTypes = Self (rawValue: 1 << 4)
37+
public static let nonescapableTypes = Self (rawValue: 1 << 3)
4138

4239
/// Whether to enable the parsing of TransferringArgsAndResults.
43-
public static let transferringArgsAndResults = Self (rawValue: 1 << 5)
40+
public static let transferringArgsAndResults = Self (rawValue: 1 << 4)
4441
}

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3513,7 +3513,6 @@ public struct DoStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSyntaxN
35133513
}
35143514

35153515
/// The clause specifying the type of errors thrown from the 'do' block.
3516-
@_spi(ExperimentalLanguageFeatures)
35173516
public var throwsClause: ThrowsClauseSyntax? {
35183517
get {
35193518
return Syntax(self).child(at: 3)?.cast(ThrowsClauseSyntax.self)

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ public struct ThrowsClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNod
589589
/// ### Tokens
590590
///
591591
/// For syntax trees generated by the parser, this is guaranteed to be `(`.
592-
@_spi(ExperimentalLanguageFeatures)
593592
public var leftParen: TokenSyntax? {
594593
get {
595594
return Syntax(self).child(at: 3)?.cast(TokenSyntax.self)
@@ -609,7 +608,6 @@ public struct ThrowsClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNod
609608
}
610609

611610
/// The thrown error type.
612-
@_spi(ExperimentalLanguageFeatures)
613611
public var type: TypeSyntax? {
614612
get {
615613
return Syntax(self).child(at: 5)?.cast(TypeSyntax.self)
@@ -633,7 +631,6 @@ public struct ThrowsClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNod
633631
/// ### Tokens
634632
///
635633
/// For syntax trees generated by the parser, this is guaranteed to be `)`.
636-
@_spi(ExperimentalLanguageFeatures)
637634
public var rightParen: TokenSyntax? {
638635
get {
639636
return Syntax(self).child(at: 7)?.cast(TokenSyntax.self)

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -930,26 +930,23 @@ final class DeclarationTests: ParserTestCase {
930930

931931
func testTypedThrows() {
932932
assertParse(
933-
"func test() throws(any Error) -> Int { }",
934-
experimentalFeatures: [.typedThrows]
933+
"func test() throws(any Error) -> Int { }"
935934
)
936935

937936
assertParse(
938937
"""
939938
struct X {
940939
init() throws(any Error) { }
941940
}
942-
""",
943-
experimentalFeatures: [.typedThrows]
941+
"""
944942
)
945943

946944
assertParse(
947945
"func test() throws(MyError) 1️⃣async {}",
948946
diagnostics: [
949947
DiagnosticSpec(message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"])
950948
],
951-
fixedSource: "func test() async throws(MyError) {}",
952-
experimentalFeatures: [.typedThrows]
949+
fixedSource: "func test() async throws(MyError) {}"
953950
)
954951

955952
assertParse(
@@ -958,8 +955,7 @@ final class DeclarationTests: ParserTestCase {
958955
DiagnosticSpec(locationMarker: "1️⃣", message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"]),
959956
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in function"),
960957
],
961-
fixedSource: "func test() async throws (MyError) {}",
962-
experimentalFeatures: [.typedThrows]
958+
fixedSource: "func test() async throws (MyError) {}"
963959
)
964960

965961
assertParse(
@@ -968,8 +964,7 @@ final class DeclarationTests: ParserTestCase {
968964
DiagnosticSpec(locationMarker: "1️⃣", message: "expected throwing specifier; did you mean 'throws'?", fixIts: ["replace 'try' with 'throws'"]),
969965
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError) async' in function"),
970966
],
971-
fixedSource: "func test() throws (MyError) async {}",
972-
experimentalFeatures: [.typedThrows]
967+
fixedSource: "func test() throws (MyError) async {}"
973968
)
974969

975970
assertParse(
@@ -979,17 +974,15 @@ final class DeclarationTests: ParserTestCase {
979974
DiagnosticSpec(locationMarker: "2️⃣", message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"]),
980975
DiagnosticSpec(locationMarker: "3️⃣", message: "unexpected code '(MyError)' in function"),
981976
],
982-
fixedSource: "func test() async throws (MyError) {}",
983-
experimentalFeatures: [.typedThrows]
977+
fixedSource: "func test() async throws (MyError) {}"
984978
)
985979

986980
assertParse(
987981
"func test() throws(MyError) 1️⃣await {}",
988982
diagnostics: [
989983
DiagnosticSpec(locationMarker: "1️⃣", message: "'await' must precede 'throws'", fixIts: ["move 'await' in front of 'throws'"])
990984
],
991-
fixedSource: "func test() async throws(MyError) {}",
992-
experimentalFeatures: [.typedThrows]
985+
fixedSource: "func test() async throws(MyError) {}"
993986
)
994987

995988
assertParse(
@@ -998,8 +991,7 @@ final class DeclarationTests: ParserTestCase {
998991
DiagnosticSpec(locationMarker: "1️⃣", message: "'await' must precede 'throws'", fixIts: ["move 'await' in front of 'throws'"]),
999992
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in function"),
1000993
],
1001-
fixedSource: "func test() async throws (MyError) {}",
1002-
experimentalFeatures: [.typedThrows]
994+
fixedSource: "func test() async throws (MyError) {}"
1003995
)
1004996

1005997
assertParse(
@@ -1008,8 +1000,7 @@ final class DeclarationTests: ParserTestCase {
10081000
DiagnosticSpec(locationMarker: "1️⃣", message: "expected throwing specifier; did you mean 'throws'?", fixIts: ["replace 'try' with 'throws'"]),
10091001
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError) await' in function"),
10101002
],
1011-
fixedSource: "func test() throws (MyError) await {}",
1012-
experimentalFeatures: [.typedThrows]
1003+
fixedSource: "func test() throws (MyError) await {}"
10131004
)
10141005

10151006
assertParse(
@@ -1018,16 +1009,14 @@ final class DeclarationTests: ParserTestCase {
10181009
DiagnosticSpec(locationMarker: "1️⃣", message: "expected throwing specifier; did you mean 'throws'?", fixIts: ["replace 'try' with 'throws'"]),
10191010
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in function"),
10201011
],
1021-
fixedSource: "func test() awaitthrows (MyError) {}", // FIXME: spacing
1022-
experimentalFeatures: [.typedThrows]
1012+
fixedSource: "func test() awaitthrows (MyError) {}" // FIXME: spacing
10231013
)
10241014

10251015
assertParse(
10261016
"func test() async1️⃣(MyError) {}",
10271017
diagnostics: [
10281018
DiagnosticSpec(message: "unexpected code '(MyError)' in function")
1029-
],
1030-
experimentalFeatures: [.typedThrows]
1019+
]
10311020
)
10321021

10331022
assertParse(
@@ -1036,8 +1025,7 @@ final class DeclarationTests: ParserTestCase {
10361025
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'await' with 'async'"]),
10371026
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in function"),
10381027
],
1039-
fixedSource: "func test() async (MyError) {}",
1040-
experimentalFeatures: [.typedThrows]
1028+
fixedSource: "func test() async (MyError) {}"
10411029
)
10421030

10431031
assertParse(
@@ -1046,22 +1034,19 @@ final class DeclarationTests: ParserTestCase {
10461034
DiagnosticSpec(locationMarker: "1️⃣", message: "expected throwing specifier; did you mean 'throws'?", fixIts: ["replace 'try' with 'throws'"]),
10471035
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in function"),
10481036
],
1049-
fixedSource: "func test() throws (MyError) {}",
1050-
experimentalFeatures: [.typedThrows]
1037+
fixedSource: "func test() throws (MyError) {}"
10511038
)
10521039

10531040
assertParse(
1054-
"func test() throws(MyError) {}",
1055-
experimentalFeatures: [.typedThrows]
1041+
"func test() throws(MyError) {}"
10561042
)
10571043

10581044
assertParse(
10591045
"func test() throws(MyError)1️⃣async {}", // no space between closing parenthesis and `async`
10601046
diagnostics: [
10611047
DiagnosticSpec(message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"])
10621048
],
1063-
fixedSource: "func test() async throws(MyError){}",
1064-
experimentalFeatures: [.typedThrows]
1049+
fixedSource: "func test() async throws(MyError){}"
10651050
)
10661051
}
10671052

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,46 +2823,40 @@ final class StatementExpressionTests: ParserTestCase {
28232823
diagnostics: [
28242824
DiagnosticSpec(message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"])
28252825
],
2826-
fixedSource: "[() async throws(MyError) -> Void]()",
2827-
experimentalFeatures: .typedThrows
2826+
fixedSource: "[() async throws(MyError) -> Void]()"
28282827
)
28292828
assertParse(
28302829
"[() throws 1️⃣async2️⃣(MyError) -> Void]()",
28312830
diagnostics: [
28322831
DiagnosticSpec(locationMarker: "1️⃣", message: "'async' must precede 'throws'", fixIts: ["move 'async' in front of 'throws'"]),
28332832
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in array element"),
28342833
],
2835-
fixedSource: "[() async throws (MyError) -> Void]()",
2836-
experimentalFeatures: .typedThrows
2834+
fixedSource: "[() async throws (MyError) -> Void]()"
28372835
)
28382836
assertParse(
28392837
"[() 1️⃣try(MyError) async -> Void]()",
28402838
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2841-
fixedSource: "[(), try(MyError) async -> Void]()",
2842-
experimentalFeatures: .typedThrows
2839+
fixedSource: "[(), try(MyError) async -> Void]()"
28432840
)
28442841
assertParse(
28452842
"[() 1️⃣try async(MyError) -> Void]()",
28462843
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2847-
fixedSource: "[(), try async(MyError) -> Void]()",
2848-
experimentalFeatures: .typedThrows
2844+
fixedSource: "[(), try async(MyError) -> Void]()"
28492845
)
28502846
assertParse(
28512847
"[() throws(MyError) 1️⃣await -> Void]()",
28522848
diagnostics: [
28532849
DiagnosticSpec(locationMarker: "1️⃣", message: "'await' must precede 'throws'", fixIts: ["move 'await' in front of 'throws'"])
28542850
],
2855-
fixedSource: "[() async throws(MyError) -> Void]()",
2856-
experimentalFeatures: .typedThrows
2851+
fixedSource: "[() async throws(MyError) -> Void]()"
28572852
)
28582853
assertParse(
28592854
"[() throws 1️⃣await2️⃣(MyError) -> Void]()",
28602855
diagnostics: [
28612856
DiagnosticSpec(locationMarker: "1️⃣", message: "'await' must precede 'throws'", fixIts: ["move 'await' in front of 'throws'"]),
28622857
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code '(MyError)' in array element"),
28632858
],
2864-
fixedSource: "[() async throws (MyError) -> Void]()",
2865-
experimentalFeatures: .typedThrows
2859+
fixedSource: "[() async throws (MyError) -> Void]()"
28662860
)
28672861
assertParse(
28682862
"[() 1️⃣try(MyError) 2️⃣await 3️⃣-> Void]()",
@@ -2883,44 +2877,36 @@ final class StatementExpressionTests: ParserTestCase {
28832877
fixIts: ["insert expression"]
28842878
),
28852879
],
2886-
fixedSource: "[(), try(MyError), await <#expression#> -> Void]()",
2887-
experimentalFeatures: .typedThrows
2880+
fixedSource: "[(), try(MyError), await <#expression#> -> Void]()"
28882881
)
28892882
assertParse(
28902883
"[() 1️⃣try await(MyError) -> Void]()",
28912884
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2892-
fixedSource: "[(), try await(MyError) -> Void]()",
2893-
experimentalFeatures: .typedThrows
2885+
fixedSource: "[(), try await(MyError) -> Void]()"
28942886
)
28952887
assertParse(
28962888
"[() 1️⃣async(MyError) -> Void]()",
28972889
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2898-
fixedSource: "[(), async(MyError) -> Void]()",
2899-
experimentalFeatures: .typedThrows
2890+
fixedSource: "[(), async(MyError) -> Void]()"
29002891
)
29012892
assertParse(
29022893
"[() 1️⃣await(MyError) -> Void]()",
29032894
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2904-
fixedSource: "[(), await(MyError) -> Void]()",
2905-
experimentalFeatures: .typedThrows
2895+
fixedSource: "[(), await(MyError) -> Void]()"
29062896
)
29072897
assertParse(
29082898
"[() 1️⃣try(MyError) -> Void]()",
29092899
diagnostics: [DiagnosticSpec(message: "expected ',' in array element", fixIts: ["insert ','"])],
2910-
fixedSource: "[(), try(MyError) -> Void]()",
2911-
experimentalFeatures: .typedThrows
2900+
fixedSource: "[(), try(MyError) -> Void]()"
29122901
)
29132902
assertParse(
2914-
"[() throws(MyError) -> Void]()",
2915-
experimentalFeatures: .typedThrows
2903+
"[() throws(MyError) -> Void]()"
29162904
)
29172905
assertParse(
2918-
"X<() throws(MyError) -> Int>()",
2919-
experimentalFeatures: .typedThrows
2906+
"X<() throws(MyError) -> Int>()"
29202907
)
29212908
assertParse(
2922-
"X<() async throws(MyError) -> Int>()",
2923-
experimentalFeatures: .typedThrows
2909+
"X<() async throws(MyError) -> Int>()"
29242910
)
29252911
}
29262912

Tests/SwiftParserTest/StatementTests.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,26 +902,23 @@ final class StatementTests: ParserTestCase {
902902
do throws(any Error) {
903903
throw myError
904904
}
905-
""",
906-
experimentalFeatures: [.typedThrows]
905+
"""
907906
)
908907

909908
assertParse(
910909
"""
911910
do throws(MyError) {
912911
throw myError
913912
}
914-
""",
915-
experimentalFeatures: [.typedThrows]
913+
"""
916914
)
917915

918916
assertParse(
919917
"""
920918
do throws {
921919
throw myError
922920
}
923-
""",
924-
experimentalFeatures: [.typedThrows]
921+
"""
925922
)
926923
}
927924
}

0 commit comments

Comments
 (0)