-
Notifications
You must be signed in to change notification settings - Fork 458
Typed throws #2219
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
Typed throws #2219
Changes from all commits
8e75584
a602fdd
d6e4880
7557530
93f2a15
fd475cb
9e7cb5e
c595980
7af0beb
f3168d0
9d7be37
1df2e44
204162a
011ddd9
15ae54e
a3c2de2
b243260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,34 @@ public let COMMON_NODES: [Node] = [ | |
] | ||
), | ||
|
||
Node( | ||
kind: .thrownTypeClause, | ||
base: .syntax, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a doc comments for this node and its children? |
||
nameForDiagnostics: "thrown type clause", | ||
documentation: "The specific error type that a function can throw.", | ||
traits: [ | ||
"Parenthesized" | ||
], | ||
children: [ | ||
Child( | ||
name: "leftParen", | ||
kind: .token(choices: [.token(.leftParen)]), | ||
documentation: "The '(' to open the thrown type clause." | ||
), | ||
Child( | ||
name: "type", | ||
kind: .node(kind: .type), | ||
nameForDiagnostics: "thrown type", | ||
documentation: "The thrown error type." | ||
), | ||
Child( | ||
name: "rightParen", | ||
kind: .token(choices: [.token(.rightParen)]), | ||
documentation: "The ')' to closure the thrown type clause." | ||
), | ||
] | ||
), | ||
|
||
Node( | ||
kind: .accessorEffectSpecifiers, | ||
base: .syntax, | ||
|
@@ -99,6 +127,13 @@ public let COMMON_NODES: [Node] = [ | |
documentation: "The `throws` keyword.", | ||
isOptional: true | ||
), | ||
Child( | ||
name: "thrownError", | ||
kind: .node(kind: .thrownTypeClause), | ||
experimentalFeature: .typedThrows, | ||
documentation: "The specific error type thrown by this accessor.", | ||
isOptional: true | ||
), | ||
] | ||
), | ||
|
||
|
@@ -122,6 +157,13 @@ public let COMMON_NODES: [Node] = [ | |
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.", | ||
isOptional: true | ||
), | ||
] | ||
), | ||
|
||
|
@@ -324,6 +366,13 @@ public let COMMON_NODES: [Node] = [ | |
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.", | ||
isOptional: true | ||
), | ||
] | ||
), | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,11 +800,18 @@ extension Parser.Lookahead { | |
return true | ||
} | ||
|
||
if self.at(anyIn: EffectSpecifier.self) != nil { | ||
if let effect = self.at(anyIn: EffectSpecifier.self) { | ||
if self.peek().rawTokenKind == .arrow { | ||
return true | ||
} | ||
|
||
if effect.spec.isThrowsSpecifier && self.peek().rawTokenKind == .leftParen { | ||
var backtrack = self.lookahead() | ||
backtrack.consumeAnyToken() | ||
backtrack.skipSingle() | ||
return backtrack.atFunctionTypeArrow() | ||
} | ||
Comment on lines
+808
to
+813
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this doesn’t handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it doesn’t. The following test fails to parse assertParse(
"[() async throws(MyError) -> Void]()"
) |
||
|
||
if peek(isAtAnyIn: EffectSpecifier.self) != nil { | ||
var backtrack = self.lookahead() | ||
backtrack.consumeAnyToken() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should mark this node as experimental.