@@ -29,6 +29,14 @@ using namespace constraints;
29
29
30
30
FailureDiagnostic::~FailureDiagnostic () {}
31
31
32
+ bool FailureDiagnostic::diagnose (bool asNote) {
33
+ return asNote ? diagnoseAsNote () : diagnoseAsError ();
34
+ }
35
+
36
+ bool FailureDiagnostic::diagnoseAsNote () {
37
+ return false ;
38
+ }
39
+
32
40
std::pair<Expr *, bool > FailureDiagnostic::computeAnchor () const {
33
41
auto &cs = getConstraintSystem ();
34
42
@@ -116,21 +124,14 @@ const DeclContext *RequirementFailure::getRequirementDC() const {
116
124
return AffectedDecl->getAsGenericContext ();
117
125
}
118
126
119
- bool RequirementFailure::diagnose ( bool asNote ) {
127
+ bool RequirementFailure::diagnoseAsError ( ) {
120
128
if (!canDiagnoseFailure ())
121
129
return false ;
122
130
123
131
auto *anchor = getAnchor ();
124
132
const auto *reqDC = getRequirementDC ();
125
133
auto *genericCtx = AffectedDecl->getAsGenericContext ();
126
134
127
- if (asNote) {
128
- const auto &req = getRequirement ();
129
- emitDiagnostic (reqDC->getAsDecl (), getDiagnosticAsNote (), getLHS (),
130
- getRHS (), req.getFirstType (), req.getSecondType (), " " );
131
- return true ;
132
- }
133
-
134
135
if (reqDC != genericCtx) {
135
136
auto *NTD = reqDC->getSelfNominalTypeDecl ();
136
137
emitDiagnostic (anchor->getLoc (), getDiagnosticInRereference (),
@@ -147,6 +148,15 @@ bool RequirementFailure::diagnose(bool asNote) {
147
148
return true ;
148
149
}
149
150
151
+ bool RequirementFailure::diagnoseAsNote () {
152
+ const auto &req = getRequirement ();
153
+ const auto *reqDC = getRequirementDC ();
154
+
155
+ emitDiagnostic (reqDC->getAsDecl (), getDiagnosticAsNote (), getLHS (), getRHS (),
156
+ req.getFirstType (), req.getSecondType (), " " );
157
+ return true ;
158
+ }
159
+
150
160
void RequirementFailure::emitRequirementNote (const Decl *anchor) const {
151
161
auto &req = getRequirement ();
152
162
@@ -166,13 +176,10 @@ void RequirementFailure::emitRequirementNote(const Decl *anchor) const {
166
176
req.getFirstType (), getLHS (), req.getSecondType (), getRHS ());
167
177
}
168
178
169
- bool MissingConformanceFailure::diagnose ( bool asNote ) {
179
+ bool MissingConformanceFailure::diagnoseAsError ( ) {
170
180
if (!canDiagnoseFailure ())
171
181
return false ;
172
182
173
- if (asNote)
174
- return RequirementFailure::diagnose (asNote);
175
-
176
183
auto *anchor = getAnchor ();
177
184
auto ownerType = getOwnerType ();
178
185
auto nonConformingType = getLHS ();
@@ -230,25 +237,18 @@ bool MissingConformanceFailure::diagnose(bool asNote) {
230
237
231
238
// If none of the special cases could be diagnosed,
232
239
// let's fallback to the most general diagnostic.
233
- return RequirementFailure::diagnose ();
240
+ return RequirementFailure::diagnoseAsError ();
234
241
}
235
242
236
- bool LabelingFailure::diagnose (bool asNote) {
237
- if (asNote)
238
- return false ;
239
-
243
+ bool LabelingFailure::diagnoseAsError () {
240
244
auto &cs = getConstraintSystem ();
241
245
auto *call = cast<CallExpr>(getAnchor ());
242
246
return diagnoseArgumentLabelError (cs.getASTContext (), call->getArg (),
243
247
CorrectLabels,
244
248
isa<SubscriptExpr>(call->getFn ()));
245
249
}
246
250
247
- bool NoEscapeFuncToTypeConversionFailure::diagnose (bool asNote) {
248
- // Can't diagnose this problem as a note at the moment.
249
- if (asNote)
250
- return false ;
251
-
251
+ bool NoEscapeFuncToTypeConversionFailure::diagnoseAsError () {
252
252
auto *anchor = getAnchor ();
253
253
254
254
if (ConvertTo) {
@@ -271,9 +271,8 @@ bool NoEscapeFuncToTypeConversionFailure::diagnose(bool asNote) {
271
271
return true ;
272
272
}
273
273
274
- bool MissingForcedDowncastFailure::diagnose (bool asNote) {
275
- // Can't diagnose this problem as a note at the moment.
276
- if (hasComplexLocator () || asNote)
274
+ bool MissingForcedDowncastFailure::diagnoseAsError () {
275
+ if (hasComplexLocator ())
277
276
return false ;
278
277
279
278
auto &TC = getTypeChecker ();
@@ -313,9 +312,8 @@ bool MissingForcedDowncastFailure::diagnose(bool asNote) {
313
312
}
314
313
}
315
314
316
- bool MissingAddressOfFailure::diagnose (bool asNote) {
317
- // Can't diagnose this problem as a note at the moment.
318
- if (hasComplexLocator () || asNote)
315
+ bool MissingAddressOfFailure::diagnoseAsError () {
316
+ if (hasComplexLocator ())
319
317
return false ;
320
318
321
319
auto *anchor = getAnchor ();
@@ -325,9 +323,8 @@ bool MissingAddressOfFailure::diagnose(bool asNote) {
325
323
return true ;
326
324
}
327
325
328
- bool MissingExplicitConversionFailure::diagnose (bool asNote) {
329
- // Can't diagnose this problem as a note at the moment.
330
- if (hasComplexLocator () || asNote)
326
+ bool MissingExplicitConversionFailure::diagnoseAsError () {
327
+ if (hasComplexLocator ())
331
328
return false ;
332
329
333
330
auto *DC = getDC ();
@@ -383,9 +380,8 @@ bool MissingExplicitConversionFailure::diagnose(bool asNote) {
383
380
return true ;
384
381
}
385
382
386
- bool MemberAccessOnOptionalBaseFailure::diagnose (bool asNote) {
387
- // Can't diagnose this problem as a note at the moment.
388
- if (hasComplexLocator () || asNote)
383
+ bool MemberAccessOnOptionalBaseFailure::diagnoseAsError () {
384
+ if (hasComplexLocator ())
389
385
return false ;
390
386
391
387
auto *anchor = getAnchor ();
@@ -537,9 +533,8 @@ static bool diagnoseUnwrap(ConstraintSystem &CS, Expr *expr, Type type) {
537
533
return true ;
538
534
}
539
535
540
- bool MissingOptionalUnwrapFailure::diagnose (bool asNote) {
541
- // Can't diagnose this problem as a note at the moment.
542
- if (hasComplexLocator () || asNote)
536
+ bool MissingOptionalUnwrapFailure::diagnoseAsError () {
537
+ if (hasComplexLocator ())
543
538
return false ;
544
539
545
540
auto *anchor = getAnchor ();
@@ -555,11 +550,7 @@ bool MissingOptionalUnwrapFailure::diagnose(bool asNote) {
555
550
return true ;
556
551
}
557
552
558
- bool RValueTreatedAsLValueFailure::diagnose (bool asNote) {
559
- // Can't diagnose this problem as a note at the moment.
560
- if (asNote)
561
- return false ;
562
-
553
+ bool RValueTreatedAsLValueFailure::diagnoseAsError () {
563
554
Diag<StringRef> subElementDiagID;
564
555
Diag<Type> rvalueDiagID;
565
556
Expr *diagExpr = getLocator ()->getAnchor ();
0 commit comments