@@ -222,12 +222,17 @@ class RequirementFailure : public FailureDiagnostic {
222
222
// / to diagnose failures related to arguments.
223
223
const ApplyExpr *Apply = nullptr ;
224
224
225
+ // / Types associated with requirement constraint this
226
+ // / failure originates from.
227
+ Type LHS, RHS;
228
+
225
229
public:
226
230
RequirementFailure (ConstraintSystem &cs, Expr *expr, RequirementKind kind,
227
- ConstraintLocator *locator)
231
+ Type lhs, Type rhs, ConstraintLocator *locator)
228
232
: FailureDiagnostic(expr, cs, locator),
229
233
Conformance (getConformanceForConditionalReq(locator)),
230
- Signature(getSignature(locator)), AffectedDecl(getDeclRef()) {
234
+ Signature(getSignature(locator)), AffectedDecl(getDeclRef()),
235
+ LHS(resolveType(lhs)), RHS(resolveType(rhs)) {
231
236
assert (locator);
232
237
assert (isConditional () || Signature);
233
238
assert (AffectedDecl);
@@ -267,8 +272,8 @@ class RequirementFailure : public FailureDiagnostic {
267
272
// / Generic requirement associated with the failure.
268
273
const Requirement &getRequirement () const ;
269
274
270
- virtual Type getLHS () const = 0;
271
- virtual Type getRHS () const = 0;
275
+ Type getLHS () const { return LHS; }
276
+ Type getRHS () const { return RHS; }
272
277
273
278
bool diagnoseAsError () override ;
274
279
bool diagnoseAsNote () override ;
@@ -358,27 +363,15 @@ class RequirementFailure : public FailureDiagnostic {
358
363
// / foo(S())
359
364
// / ```
360
365
class MissingConformanceFailure final : public RequirementFailure {
361
- Type NonConformingType;
362
- Type ProtocolType;
363
-
364
366
public:
365
367
MissingConformanceFailure (Expr *expr, ConstraintSystem &cs,
366
368
ConstraintLocator *locator,
367
369
std::pair<Type, Type> conformance)
368
- : RequirementFailure(cs, expr, RequirementKind::Conformance, locator),
369
- NonConformingType (conformance.first), ProtocolType(conformance.second) {
370
- }
370
+ : RequirementFailure(cs, expr, RequirementKind::Conformance,
371
+ conformance.first, conformance.second, locator) {}
371
372
372
373
bool diagnoseAsError () override ;
373
374
374
- private:
375
- // / The type which was expected, by one of the generic requirements,
376
- // / to conform to associated protocol.
377
- Type getLHS () const override { return NonConformingType; }
378
-
379
- // / The protocol generic requirement expected associated type to conform to.
380
- Type getRHS () const override { return ProtocolType; }
381
-
382
375
protected:
383
376
DiagOnDecl getDiagnosticOnDecl () const override {
384
377
return diag::type_does_not_conform_decl_owner;
@@ -448,16 +441,11 @@ class GenericArgumentsMismatchFailure final : public FailureDiagnostic {
448
441
// /
449
442
// / `S.T` is not the same type as `Int`, which is required by `foo`.
450
443
class SameTypeRequirementFailure final : public RequirementFailure {
451
- Type LHS, RHS;
452
-
453
444
public:
454
445
SameTypeRequirementFailure (Expr *expr, ConstraintSystem &cs, Type lhs,
455
446
Type rhs, ConstraintLocator *locator)
456
- : RequirementFailure(cs, expr, RequirementKind::SameType, locator),
457
- LHS (lhs), RHS(rhs) {}
458
-
459
- Type getLHS () const override { return LHS; }
460
- Type getRHS () const override { return RHS; }
447
+ : RequirementFailure(cs, expr, RequirementKind::SameType, lhs, rhs,
448
+ locator) {}
461
449
462
450
protected:
463
451
DiagOnDecl getDiagnosticOnDecl () const override {
@@ -487,16 +475,11 @@ class SameTypeRequirementFailure final : public RequirementFailure {
487
475
// /
488
476
// / `A` is not the superclass of `B`, which is required by `foo<T>`.
489
477
class SuperclassRequirementFailure final : public RequirementFailure {
490
- Type LHS, RHS;
491
-
492
478
public:
493
479
SuperclassRequirementFailure (Expr *expr, ConstraintSystem &cs, Type lhs,
494
480
Type rhs, ConstraintLocator *locator)
495
- : RequirementFailure(cs, expr, RequirementKind::Superclass, locator),
496
- LHS (lhs), RHS(rhs) {}
497
-
498
- Type getLHS () const override { return LHS; }
499
- Type getRHS () const override { return RHS; }
481
+ : RequirementFailure(cs, expr, RequirementKind::Superclass, lhs, rhs,
482
+ locator) {}
500
483
501
484
protected:
502
485
DiagOnDecl getDiagnosticOnDecl () const override {
0 commit comments