File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -72,8 +72,17 @@ public struct Diagnostic: CustomDebugStringConvertible {
72
72
}
73
73
}
74
74
75
- public protocol DiagnosticsProviding : Error {
76
- /// The diagnostics provided by this error.
77
- /// At least one diagnostic should have `severity == .error`.
78
- var diagnostics : [ Diagnostic ] { get }
75
+ public struct DiagnosticsError : Error {
76
+ public var diagnostics : [ Diagnostic ]
77
+
78
+ /// The diagnostics must contain at least one with severity == `.error`.
79
+ /// Asserts if this condition is not satisfied.
80
+ public init ( diagnostics: [ Diagnostic ] ) {
81
+ self . diagnostics = diagnostics
82
+
83
+ assert (
84
+ diagnostics. contains ( where: { $0. diagMessage. severity == . error } ) ,
85
+ " at least one diagnostic must have severity == .error "
86
+ )
87
+ }
79
88
}
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ private struct ThrownErrorDiagnostic: DiagnosticMessage {
79
79
extension MacroExpansionContext {
80
80
/// Add diagnostics from the error thrown during macro expansion.
81
81
public func addDiagnostics< S: SyntaxProtocol > ( from error: Error , node: S ) {
82
- guard let diagnosticsProvider = error as? DiagnosticsProviding else {
82
+ guard let diagnosticsError = error as? DiagnosticsError else {
83
83
diagnose (
84
84
Diagnostic (
85
85
node: Syntax ( node) ,
@@ -89,13 +89,12 @@ extension MacroExpansionContext {
89
89
return
90
90
}
91
91
92
- let providedDiagnostics = diagnosticsProvider. diagnostics
93
- for diagnostic in providedDiagnostics {
92
+ for diagnostic in diagnosticsError. diagnostics {
94
93
diagnose ( diagnostic)
95
94
}
96
95
97
96
// handle possibility that none of the diagnostics was an error
98
- if !providedDiagnostics . contains (
97
+ if !diagnosticsError . diagnostics . contains (
99
98
where: { $0. diagMessage. severity == . error }
100
99
) {
101
100
diagnose (
You can’t perform that action at this time.
0 commit comments