Skip to content

Commit 7f39859

Browse files
committed
Introduce an experimental feature for typed throws
1 parent 53a73f4 commit 7f39859

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Sources/SwiftParser/Specifiers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ extension Parser {
654654
throwsKeyword = throwsKw
655655
}
656656

657-
if throwsKeyword != nil && self.at(.leftParen) {
657+
if throwsKeyword != nil && self.at(.leftParen) && experimentalFeatures.contains(.typedThrows) {
658658
thrownType = parseThrownType()
659659
}
660660

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ extension Parser.ExperimentalFeatures {
2929

3030
/// Whether to enable the parsing of 'then' statements.
3131
public static let thenStatements = Self(rawValue: 1 << 1)
32+
33+
/// Whether to enable the parsing of typed throws.
34+
public static let typedThrows = Self(rawValue: 1 << 2)
3235
}

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,17 @@ final class DeclarationTests: ParserTestCase {
893893

894894
func testTypedThrows() {
895895
assertParse(
896-
"func test() throws(any Error) -> Int { }"
896+
"func test() throws(any Error) -> Int { }",
897+
experimentalFeatures: [.typedThrows]
897898
)
898899

899900
assertParse(
900901
"""
901902
struct X {
902903
init() throws(any Error) { }
903904
}
904-
"""
905+
""",
906+
experimentalFeatures: [.typedThrows]
905907
)
906908
}
907909

Tests/SwiftParserTest/TypeTests.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_spi(RawSyntax) import SwiftParser
13+
@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftParser
1414
@_spi(RawSyntax) import SwiftSyntax
1515
import XCTest
1616

@@ -309,11 +309,18 @@ final class TypeTests: ParserTestCase {
309309
assertParse(
310310
"""
311311
{ () throws(PosixError) -> Void in }
312-
"""
312+
""",
313+
experimentalFeatures: [.typedThrows]
313314
)
314315

315-
assertParse("typealias T = () throws(PosixError) -> Void")
316+
assertParse(
317+
"typealias T = () throws(PosixError) -> Void",
318+
experimentalFeatures: [.typedThrows]
319+
)
316320

317-
assertParse("[() throws(PosixError) -> Void]()")
321+
assertParse(
322+
"[() throws(PosixError) -> Void]()",
323+
experimentalFeatures: [.typedThrows]
324+
)
318325
}
319326
}

0 commit comments

Comments
 (0)