|
19 | 19 |
|
20 | 20 | #include "swift/AST/Attr.h"
|
21 | 21 | #include "swift/AST/DeclContext.h"
|
| 22 | +#include "swift/AST/DiagnosticEngine.h" |
22 | 23 | #include "swift/AST/GenericSignature.h"
|
23 | 24 | #include "swift/AST/Identifier.h"
|
24 | 25 | #include "swift/AST/Type.h"
|
@@ -195,17 +196,35 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
|
195 | 196 | /// A TypeRepr for a type with a syntax error. Can be used both as a
|
196 | 197 | /// top-level TypeRepr and as a part of other TypeRepr.
|
197 | 198 | ///
|
198 |
| -/// The client should make sure to emit a diagnostic at the construction time |
199 |
| -/// (in the parser). All uses of this type should be ignored and not |
200 |
| -/// re-diagnosed. |
| 199 | +/// The client can either emit a detailed diagnostic at the construction time |
| 200 | +/// (in the parser) or store a zero-arg diagnostic in this TypeRepr to be |
| 201 | +/// emitted after parsing, during type resolution. |
| 202 | +/// |
| 203 | +/// All uses of this type should be ignored and not re-diagnosed. |
201 | 204 | class ErrorTypeRepr : public TypeRepr {
|
202 | 205 | SourceRange Range;
|
| 206 | + llvm::Optional<ZeroArgDiagnostic> DelayedDiag; |
| 207 | + |
| 208 | + ErrorTypeRepr(SourceRange Range, llvm::Optional<ZeroArgDiagnostic> Diag) |
| 209 | + : TypeRepr(TypeReprKind::Error), Range(Range), DelayedDiag(Diag) {} |
203 | 210 |
|
204 | 211 | public:
|
205 |
| - ErrorTypeRepr() : TypeRepr(TypeReprKind::Error) {} |
206 |
| - ErrorTypeRepr(SourceLoc Loc) : TypeRepr(TypeReprKind::Error), Range(Loc) {} |
207 |
| - ErrorTypeRepr(SourceRange Range) |
208 |
| - : TypeRepr(TypeReprKind::Error), Range(Range) {} |
| 212 | + static ErrorTypeRepr * |
| 213 | + create(ASTContext &Context, SourceRange Range, |
| 214 | + llvm::Optional<ZeroArgDiagnostic> DelayedDiag = llvm::None) { |
| 215 | + assert((!DelayedDiag || Range) && "diagnostic needs a location"); |
| 216 | + return new (Context) ErrorTypeRepr(Range, DelayedDiag); |
| 217 | + } |
| 218 | + |
| 219 | + static ErrorTypeRepr * |
| 220 | + create(ASTContext &Context, SourceLoc Loc = SourceLoc(), |
| 221 | + llvm::Optional<ZeroArgDiagnostic> DelayedDiag = llvm::None) { |
| 222 | + return create(Context, SourceRange(Loc), DelayedDiag); |
| 223 | + } |
| 224 | + |
| 225 | + /// If there is a delayed diagnostic stored in this TypeRepr, consumes and |
| 226 | + /// emits that diagnostic. |
| 227 | + void dischargeDiagnostic(ASTContext &Context); |
209 | 228 |
|
210 | 229 | static bool classof(const TypeRepr *T) {
|
211 | 230 | return T->getKind() == TypeReprKind::Error;
|
|
0 commit comments