@@ -160,10 +160,23 @@ class RequirementFailure : public FailureDiagnostic {
160
160
const ApplyExpr *Apply = nullptr ;
161
161
162
162
public:
163
- RequirementFailure (Expr *expr, ConstraintSystem &cs ,
163
+ RequirementFailure (ConstraintSystem &cs, Expr *expr, RequirementKind kind ,
164
164
ConstraintLocator *locator)
165
165
: FailureDiagnostic(expr, cs, locator), AffectedDecl(getDeclRef()) {
166
+ assert (locator);
166
167
assert (AffectedDecl);
168
+
169
+ auto path = locator->getPath ();
170
+ assert (!path.empty ());
171
+
172
+ auto &last = path.back ();
173
+ assert (last.getKind () == ConstraintLocator::TypeParameterRequirement);
174
+ assert (static_cast <RequirementKind>(last.getValue2 ()) == kind);
175
+
176
+ // It's possible sometimes not to have no base expression.
177
+ if (!expr)
178
+ return ;
179
+
167
180
auto *anchor = getAnchor ();
168
181
expr->forEachChildExpr ([&](Expr *subExpr) -> Expr * {
169
182
auto *AE = dyn_cast<ApplyExpr>(subExpr);
@@ -246,7 +259,7 @@ class MissingConformanceFailure final : public RequirementFailure {
246
259
MissingConformanceFailure (Expr *expr, ConstraintSystem &cs,
247
260
ConstraintLocator *locator,
248
261
std::pair<Type, ProtocolDecl *> conformance)
249
- : RequirementFailure(expr, cs , locator),
262
+ : RequirementFailure(cs, expr, RequirementKind::Conformance , locator),
250
263
NonConformingType (conformance.first), Protocol(conformance.second) {}
251
264
252
265
bool diagnoseAsError () override ;
@@ -294,7 +307,8 @@ class SameTypeRequirementFailure final : public RequirementFailure {
294
307
public:
295
308
SameTypeRequirementFailure (Expr *expr, ConstraintSystem &cs, Type lhs,
296
309
Type rhs, ConstraintLocator *locator)
297
- : RequirementFailure(expr, cs, locator), LHS(lhs), RHS(rhs) {}
310
+ : RequirementFailure(cs, expr, RequirementKind::SameType, locator),
311
+ LHS (lhs), RHS(rhs) {}
298
312
299
313
Type getLHS () const override { return LHS; }
300
314
Type getRHS () const override { return RHS; }
@@ -332,7 +346,8 @@ class SuperclassRequirementFailure final : public RequirementFailure {
332
346
public:
333
347
SuperclassRequirementFailure (Expr *expr, ConstraintSystem &cs, Type lhs,
334
348
Type rhs, ConstraintLocator *locator)
335
- : RequirementFailure(expr, cs, locator), LHS(lhs), RHS(rhs) {}
349
+ : RequirementFailure(cs, expr, RequirementKind::Superclass, locator),
350
+ LHS (lhs), RHS(rhs) {}
336
351
337
352
Type getLHS () const override { return LHS; }
338
353
Type getRHS () const override { return RHS; }
0 commit comments