@@ -597,21 +597,36 @@ class RelabelArguments final
597
597
}
598
598
};
599
599
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
+
600
619
// / Add a new conformance to the type to satisfy a requirement.
601
- class MissingConformance final : public ConstraintFix {
620
+ class MissingConformance final : public RequirementFix {
602
621
// Determines whether given protocol type comes from the context e.g.
603
622
// assignment destination or argument comparison.
604
623
bool IsContextual;
605
624
606
- Type NonConformingType;
607
- // This could either be a protocol or protocol composition.
608
- Type ProtocolType;
609
-
610
625
MissingConformance (ConstraintSystem &cs, bool isContextual, Type type,
611
626
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 ) {}
615
630
616
631
public:
617
632
std::string getName () const override {
@@ -630,9 +645,9 @@ class MissingConformance final : public ConstraintFix {
630
645
Type protocolType,
631
646
ConstraintLocator *locator);
632
647
633
- Type getNonConformingType () { return NonConformingType ; }
648
+ Type getNonConformingType () const { return LHS ; }
634
649
635
- Type getProtocolType () { return ProtocolType ; }
650
+ Type getProtocolType () const { return RHS ; }
636
651
637
652
bool isEqual (const ConstraintFix *other) const ;
638
653
@@ -643,13 +658,11 @@ class MissingConformance final : public ConstraintFix {
643
658
644
659
// / Skip same-type generic requirement constraint,
645
660
// / and assume that types are equal.
646
- class SkipSameTypeRequirement final : public ConstraintFix {
647
- Type LHS, RHS;
648
-
661
+ class SkipSameTypeRequirement final : public RequirementFix {
649
662
SkipSameTypeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
650
663
ConstraintLocator *locator)
651
- : ConstraintFix (cs, FixKind::SkipSameTypeRequirement, locator), LHS(lhs) ,
652
- RHS (rhs ) {}
664
+ : RequirementFix (cs, FixKind::SkipSameTypeRequirement, lhs, rhs ,
665
+ locator ) {}
653
666
654
667
public:
655
668
std::string getName () const override {
@@ -658,9 +671,6 @@ class SkipSameTypeRequirement final : public ConstraintFix {
658
671
659
672
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
660
673
661
- Type lhsType () { return LHS; }
662
- Type rhsType () { return RHS; }
663
-
664
674
static SkipSameTypeRequirement *create (ConstraintSystem &cs, Type lhs,
665
675
Type rhs, ConstraintLocator *locator);
666
676
@@ -673,13 +683,11 @@ class SkipSameTypeRequirement final : public ConstraintFix {
673
683
// /
674
684
// / A same shape requirement can be inferred from a generic requirement,
675
685
// / or from a pack expansion expression.
676
- class SkipSameShapeRequirement final : public ConstraintFix {
677
- Type LHS, RHS;
678
-
686
+ class SkipSameShapeRequirement final : public RequirementFix {
679
687
SkipSameShapeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
680
688
ConstraintLocator *locator)
681
- : ConstraintFix (cs, FixKind::SkipSameShapeRequirement, locator), LHS(lhs) ,
682
- RHS (rhs ) {}
689
+ : RequirementFix (cs, FixKind::SkipSameShapeRequirement, lhs, rhs ,
690
+ locator ) {}
683
691
684
692
public:
685
693
std::string getName () const override {
@@ -688,9 +696,6 @@ class SkipSameShapeRequirement final : public ConstraintFix {
688
696
689
697
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
690
698
691
- Type lhsType () { return LHS; }
692
- Type rhsType () { return RHS; }
693
-
694
699
static SkipSameShapeRequirement *create (ConstraintSystem &cs, Type lhs,
695
700
Type rhs, ConstraintLocator *locator);
696
701
@@ -701,13 +706,11 @@ class SkipSameShapeRequirement final : public ConstraintFix {
701
706
702
707
// / Skip 'superclass' generic requirement constraint,
703
708
// / and assume that types are equal.
704
- class SkipSuperclassRequirement final : public ConstraintFix {
705
- Type LHS, RHS;
706
-
709
+ class SkipSuperclassRequirement final : public RequirementFix {
707
710
SkipSuperclassRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
708
711
ConstraintLocator *locator)
709
- : ConstraintFix (cs, FixKind::SkipSuperclassRequirement, locator) ,
710
- LHS (lhs), RHS(rhs ) {}
712
+ : RequirementFix (cs, FixKind::SkipSuperclassRequirement, lhs, rhs ,
713
+ locator ) {}
711
714
712
715
public:
713
716
std::string getName () const override {
0 commit comments