@@ -597,21 +597,36 @@ class RelabelArguments final
597597 }
598598};
599599
600+ class RequirementFix : public ConstraintFix {
601+ protected:
602+ Type LHS;
603+ Type RHS;
604+
605+ RequirementFix (ConstraintSystem &cs, FixKind kind, Type lhs, Type rhs,
606+ ConstraintLocator *locator)
607+ : ConstraintFix(cs, kind, locator), LHS(lhs), RHS(rhs) {}
608+
609+ public:
610+ std::string getName () const override = 0;
611+
612+ Type lhsType () const { return LHS; }
613+ Type rhsType () const { return RHS; }
614+
615+ bool diagnose (const Solution &solution,
616+ bool asNote = false ) const override = 0;
617+ };
618+
600619// / Add a new conformance to the type to satisfy a requirement.
601- class MissingConformance final : public ConstraintFix {
620+ class MissingConformance final : public RequirementFix {
602621 // Determines whether given protocol type comes from the context e.g.
603622 // assignment destination or argument comparison.
604623 bool IsContextual;
605624
606- Type NonConformingType;
607- // This could either be a protocol or protocol composition.
608- Type ProtocolType;
609-
610625 MissingConformance (ConstraintSystem &cs, bool isContextual, Type type,
611626 Type protocolType, ConstraintLocator *locator)
612- : ConstraintFix (cs, FixKind::AddConformance, locator) ,
613- IsContextual (isContextual), NonConformingType(type ),
614- ProtocolType(protocolType ) {}
627+ : RequirementFix (cs, FixKind::AddConformance, type, protocolType ,
628+ locator ),
629+ IsContextual (isContextual ) {}
615630
616631public:
617632 std::string getName () const override {
@@ -630,9 +645,9 @@ class MissingConformance final : public ConstraintFix {
630645 Type protocolType,
631646 ConstraintLocator *locator);
632647
633- Type getNonConformingType () { return NonConformingType ; }
648+ Type getNonConformingType () const { return LHS ; }
634649
635- Type getProtocolType () { return ProtocolType ; }
650+ Type getProtocolType () const { return RHS ; }
636651
637652 bool isEqual (const ConstraintFix *other) const ;
638653
@@ -643,13 +658,11 @@ class MissingConformance final : public ConstraintFix {
643658
644659// / Skip same-type generic requirement constraint,
645660// / and assume that types are equal.
646- class SkipSameTypeRequirement final : public ConstraintFix {
647- Type LHS, RHS;
648-
661+ class SkipSameTypeRequirement final : public RequirementFix {
649662 SkipSameTypeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
650663 ConstraintLocator *locator)
651- : ConstraintFix (cs, FixKind::SkipSameTypeRequirement, locator), LHS(lhs) ,
652- RHS (rhs ) {}
664+ : RequirementFix (cs, FixKind::SkipSameTypeRequirement, lhs, rhs ,
665+ locator ) {}
653666
654667public:
655668 std::string getName () const override {
@@ -658,9 +671,6 @@ class SkipSameTypeRequirement final : public ConstraintFix {
658671
659672 bool diagnose (const Solution &solution, bool asNote = false ) const override ;
660673
661- Type lhsType () { return LHS; }
662- Type rhsType () { return RHS; }
663-
664674 static SkipSameTypeRequirement *create (ConstraintSystem &cs, Type lhs,
665675 Type rhs, ConstraintLocator *locator);
666676
@@ -673,13 +683,11 @@ class SkipSameTypeRequirement final : public ConstraintFix {
673683// /
674684// / A same shape requirement can be inferred from a generic requirement,
675685// / or from a pack expansion expression.
676- class SkipSameShapeRequirement final : public ConstraintFix {
677- Type LHS, RHS;
678-
686+ class SkipSameShapeRequirement final : public RequirementFix {
679687 SkipSameShapeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
680688 ConstraintLocator *locator)
681- : ConstraintFix (cs, FixKind::SkipSameShapeRequirement, locator), LHS(lhs) ,
682- RHS (rhs ) {}
689+ : RequirementFix (cs, FixKind::SkipSameShapeRequirement, lhs, rhs ,
690+ locator ) {}
683691
684692public:
685693 std::string getName () const override {
@@ -688,9 +696,6 @@ class SkipSameShapeRequirement final : public ConstraintFix {
688696
689697 bool diagnose (const Solution &solution, bool asNote = false ) const override ;
690698
691- Type lhsType () { return LHS; }
692- Type rhsType () { return RHS; }
693-
694699 static SkipSameShapeRequirement *create (ConstraintSystem &cs, Type lhs,
695700 Type rhs, ConstraintLocator *locator);
696701
@@ -701,13 +706,11 @@ class SkipSameShapeRequirement final : public ConstraintFix {
701706
702707// / Skip 'superclass' generic requirement constraint,
703708// / and assume that types are equal.
704- class SkipSuperclassRequirement final : public ConstraintFix {
705- Type LHS, RHS;
706-
709+ class SkipSuperclassRequirement final : public RequirementFix {
707710 SkipSuperclassRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
708711 ConstraintLocator *locator)
709- : ConstraintFix (cs, FixKind::SkipSuperclassRequirement, locator) ,
710- LHS (lhs), RHS(rhs ) {}
712+ : RequirementFix (cs, FixKind::SkipSuperclassRequirement, lhs, rhs ,
713+ locator ) {}
711714
712715public:
713716 std::string getName () const override {
0 commit comments