@@ -587,21 +587,38 @@ class RelabelArguments final
587
587
}
588
588
};
589
589
590
+ class RequirementFix : public ConstraintFix {
591
+ protected:
592
+ Type LHS;
593
+ Type RHS;
594
+
595
+ RequirementFix (ConstraintSystem &cs, FixKind kind, Type lhs, Type rhs,
596
+ ConstraintLocator *locator)
597
+ : ConstraintFix(cs, kind, locator), LHS(lhs), RHS(rhs) {}
598
+
599
+ public:
600
+ std::string getName () const override = 0;
601
+
602
+ Type lhsType () const { return LHS; }
603
+ Type rhsType () const { return RHS; }
604
+
605
+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override ;
606
+
607
+ bool diagnose (const Solution &solution,
608
+ bool asNote = false ) const override = 0;
609
+ };
610
+
590
611
// / Add a new conformance to the type to satisfy a requirement.
591
- class MissingConformance final : public ConstraintFix {
612
+ class MissingConformance final : public RequirementFix {
592
613
// Determines whether given protocol type comes from the context e.g.
593
614
// assignment destination or argument comparison.
594
615
bool IsContextual;
595
616
596
- Type NonConformingType;
597
- // This could either be a protocol or protocol composition.
598
- Type ProtocolType;
599
-
600
617
MissingConformance (ConstraintSystem &cs, bool isContextual, Type type,
601
618
Type protocolType, ConstraintLocator *locator)
602
- : ConstraintFix (cs, FixKind::AddConformance, locator) ,
603
- IsContextual (isContextual), NonConformingType(type ),
604
- ProtocolType(protocolType ) {}
619
+ : RequirementFix (cs, FixKind::AddConformance, type, protocolType ,
620
+ locator ),
621
+ IsContextual (isContextual ) {}
605
622
606
623
public:
607
624
std::string getName () const override {
@@ -610,8 +627,6 @@ class MissingConformance final : public ConstraintFix {
610
627
611
628
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
612
629
613
- bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override ;
614
-
615
630
static MissingConformance *forRequirement (ConstraintSystem &cs, Type type,
616
631
Type protocolType,
617
632
ConstraintLocator *locator);
@@ -620,9 +635,9 @@ class MissingConformance final : public ConstraintFix {
620
635
Type protocolType,
621
636
ConstraintLocator *locator);
622
637
623
- Type getNonConformingType () { return NonConformingType ; }
638
+ Type getNonConformingType () const { return LHS ; }
624
639
625
- Type getProtocolType () { return ProtocolType ; }
640
+ Type getProtocolType () const { return RHS ; }
626
641
627
642
bool isEqual (const ConstraintFix *other) const ;
628
643
@@ -633,13 +648,11 @@ class MissingConformance final : public ConstraintFix {
633
648
634
649
// / Skip same-type generic requirement constraint,
635
650
// / and assume that types are equal.
636
- class SkipSameTypeRequirement final : public ConstraintFix {
637
- Type LHS, RHS;
638
-
651
+ class SkipSameTypeRequirement final : public RequirementFix {
639
652
SkipSameTypeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
640
653
ConstraintLocator *locator)
641
- : ConstraintFix (cs, FixKind::SkipSameTypeRequirement, locator), LHS(lhs) ,
642
- RHS (rhs ) {}
654
+ : RequirementFix (cs, FixKind::SkipSameTypeRequirement, lhs, rhs ,
655
+ locator ) {}
643
656
644
657
public:
645
658
std::string getName () const override {
@@ -648,9 +661,6 @@ class SkipSameTypeRequirement final : public ConstraintFix {
648
661
649
662
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
650
663
651
- Type lhsType () { return LHS; }
652
- Type rhsType () { return RHS; }
653
-
654
664
static SkipSameTypeRequirement *create (ConstraintSystem &cs, Type lhs,
655
665
Type rhs, ConstraintLocator *locator);
656
666
@@ -661,13 +671,11 @@ class SkipSameTypeRequirement final : public ConstraintFix {
661
671
662
672
// / Skip same-shape generic requirement constraint,
663
673
// / and assume that types are equal.
664
- class SkipSameShapeRequirement final : public ConstraintFix {
665
- Type LHS, RHS;
666
-
674
+ class SkipSameShapeRequirement final : public RequirementFix {
667
675
SkipSameShapeRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
668
676
ConstraintLocator *locator)
669
- : ConstraintFix (cs, FixKind::SkipSameShapeRequirement, locator), LHS(lhs) ,
670
- RHS (rhs ) {}
677
+ : RequirementFix (cs, FixKind::SkipSameShapeRequirement, lhs, rhs ,
678
+ locator ) {}
671
679
672
680
public:
673
681
std::string getName () const override {
@@ -676,9 +684,6 @@ class SkipSameShapeRequirement final : public ConstraintFix {
676
684
677
685
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
678
686
679
- Type lhsType () { return LHS; }
680
- Type rhsType () { return RHS; }
681
-
682
687
static SkipSameShapeRequirement *create (ConstraintSystem &cs, Type lhs,
683
688
Type rhs, ConstraintLocator *locator);
684
689
@@ -689,13 +694,11 @@ class SkipSameShapeRequirement final : public ConstraintFix {
689
694
690
695
// / Skip 'superclass' generic requirement constraint,
691
696
// / and assume that types are equal.
692
- class SkipSuperclassRequirement final : public ConstraintFix {
693
- Type LHS, RHS;
694
-
697
+ class SkipSuperclassRequirement final : public RequirementFix {
695
698
SkipSuperclassRequirement (ConstraintSystem &cs, Type lhs, Type rhs,
696
699
ConstraintLocator *locator)
697
- : ConstraintFix (cs, FixKind::SkipSuperclassRequirement, locator) ,
698
- LHS (lhs), RHS(rhs ) {}
700
+ : RequirementFix (cs, FixKind::SkipSuperclassRequirement, lhs, rhs ,
701
+ locator ) {}
699
702
700
703
public:
701
704
std::string getName () const override {
@@ -1839,6 +1842,10 @@ class AllowInaccessibleMember final : public AllowInvalidMemberRef {
1839
1842
1840
1843
bool diagnose (const Solution &solution, bool asNote = false ) const override ;
1841
1844
1845
+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
1846
+ return diagnose (*commonFixes.front ().first );
1847
+ }
1848
+
1842
1849
static AllowInaccessibleMember *create (ConstraintSystem &cs, Type baseType,
1843
1850
ValueDecl *member, DeclNameRef name,
1844
1851
ConstraintLocator *locator);
0 commit comments