File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Sources/_SwiftSyntaxMacros Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -21,5 +21,5 @@ public protocol ExpressionMacro: Macro {
21
21
static func expansion(
22
22
of node: MacroExpansionExprSyntax ,
23
23
in context: inout MacroExpansionContext
24
- ) -> ExprSyntax
24
+ ) throws -> ExprSyntax
25
25
}
Original file line number Diff line number Diff line change 13
13
import SwiftDiagnostics
14
14
import SwiftSyntax
15
15
16
+ /// Diagnostic message used for thrown errors.
17
+ struct ThrownErrorDiagnostic : DiagnosticMessage {
18
+ let message : String
19
+
20
+ var severity : DiagnosticSeverity { . error }
21
+
22
+ var diagnosticID : MessageID {
23
+ . init( domain: " SwiftSyntaxMacros " , id: " ThrownErrorDiagnostic " )
24
+ }
25
+ }
26
+
16
27
extension MacroExpansionExprSyntax {
17
28
private func disconnectedCopy( ) -> MacroExpansionExprSyntax {
18
29
MacroExpansionExprSyntax (
@@ -41,7 +52,19 @@ extension MacroExpansionExprSyntax {
41
52
}
42
53
43
54
// Handle the rewrite.
44
- return exprMacro. expansion ( of: disconnectedCopy ( ) , in: & context)
55
+ do {
56
+ return try exprMacro. expansion ( of: disconnectedCopy ( ) , in: & context)
57
+ } catch {
58
+ // Record the error
59
+ context. diagnose (
60
+ Diagnostic (
61
+ node: Syntax ( self ) ,
62
+ message: ThrownErrorDiagnostic ( message: String ( describing: error) )
63
+ )
64
+ )
65
+
66
+ return ExprSyntax ( self )
67
+ }
45
68
}
46
69
}
47
70
You can’t perform that action at this time.
0 commit comments