@@ -652,142 +652,6 @@ bool FailureDiagnosis::diagnoseGeneralOverloadFailure(Constraint *constraint) {
652
652
return true ;
653
653
}
654
654
655
- static bool
656
- diagnoseUnresolvedDotExprTypeRequirementFailure (ConstraintSystem &cs,
657
- Constraint *constraint) {
658
- auto &TC = cs.TC ;
659
-
660
- auto *locator = constraint->getLocator ();
661
- if (!locator)
662
- return false ;
663
-
664
-
665
- auto reqElt =
666
- locator->getLastElementAs <LocatorPathElt::TypeParameterRequirement>();
667
- if (!reqElt)
668
- return false ;
669
-
670
- auto *anchor = locator->getAnchor ();
671
- if (!anchor)
672
- return false ;
673
-
674
- auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor);
675
- if (!UDE)
676
- return false ;
677
-
678
- auto ownerType = cs.getType (UDE->getBase ());
679
- if (!ownerType)
680
- return false ;
681
-
682
- ownerType = cs.simplifyType (ownerType)->getWithoutSpecifierType ();
683
- if (ownerType->hasTypeVariable () || ownerType->hasUnresolvedType ())
684
- return false ;
685
-
686
- // If we actually resolved the member to use, use it.
687
- auto loc = cs.getConstraintLocator (UDE, ConstraintLocator::Member);
688
- auto *member = cs.findResolvedMemberRef (loc);
689
- // If the problem is contextual it's diagnosed elsewhere.
690
- if (!member || !member->getAsGenericContext ())
691
- return false ;
692
-
693
- auto req = member->getAsGenericContext ()
694
- ->getGenericSignature ()
695
- ->getRequirements ()[reqElt->getIndex ()];
696
-
697
- Diag<Type, Type, Type, Type, StringRef> note;
698
- switch (req.getKind ()) {
699
- case RequirementKind::Conformance:
700
- case RequirementKind::Layout:
701
- return false ;
702
-
703
- case RequirementKind::Superclass:
704
- note = diag::candidate_types_inheritance_requirement;
705
- break ;
706
-
707
- case RequirementKind::SameType:
708
- note = diag::candidate_types_equal_requirement;
709
- break ;
710
- }
711
-
712
- TC.diagnose (UDE->getLoc (), diag::could_not_find_value_member, ownerType,
713
- UDE->getName ());
714
-
715
- auto first = cs.simplifyType (constraint->getFirstType ());
716
- auto second = cs.simplifyType (constraint->getSecondType ());
717
- auto rawFirstType = req.getFirstType ();
718
- auto rawSecondType = req.getSecondType ();
719
-
720
- TC.diagnose (member, note, first, second, rawFirstType, rawSecondType, " " );
721
-
722
- return true ;
723
- }
724
-
725
- // / Diagnose problems related to failures in constraints
726
- // / generated by `openGeneric` which represent different
727
- // / kinds of type parameter requirements.
728
- static bool diagnoseTypeRequirementFailure (ConstraintSystem &cs,
729
- Constraint *constraint) {
730
- auto &TC = cs.TC ;
731
-
732
- auto *locator = constraint->getLocator ();
733
- if (!locator)
734
- return false ;
735
-
736
- auto path = locator->getPath ();
737
- if (path.empty ())
738
- return false ;
739
-
740
- auto &last = path.back ();
741
- if (last.getKind () != ConstraintLocator::TypeParameterRequirement)
742
- return false ;
743
-
744
- auto *anchor = locator->getAnchor ();
745
- if (!anchor)
746
- return false ;
747
-
748
- auto ownerType = cs.getType (anchor);
749
-
750
- if (isa<UnresolvedMemberExpr>(anchor))
751
- ownerType = cs.getContextualType ();
752
- else if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor))
753
- ownerType = cs.getType (UDE->getBase ());
754
-
755
- if (!ownerType)
756
- return false ;
757
-
758
- ownerType = cs.simplifyType (ownerType)->getWithoutSpecifierType ();
759
- if (ownerType->hasTypeVariable () || ownerType->hasUnresolvedType ())
760
- return false ;
761
-
762
- if (diagnoseUnresolvedDotExprTypeRequirementFailure (cs, constraint))
763
- return true ;
764
-
765
- auto lhs = cs.simplifyType (constraint->getFirstType ());
766
- auto rhs = cs.simplifyType (constraint->getSecondType ());
767
-
768
- switch (constraint->getKind ()) {
769
- case ConstraintKind::ConformsTo:
770
- TC.diagnose (anchor->getLoc (), diag::type_does_not_conform_owner, ownerType,
771
- lhs, rhs);
772
- return true ;
773
-
774
- case ConstraintKind::Subtype: // superclass
775
- TC.diagnose (anchor->getLoc (), diag::type_does_not_inherit, ownerType, lhs,
776
- rhs);
777
- return true ;
778
-
779
- case ConstraintKind::Bind: { // same type
780
- TC.diagnose (anchor->getLoc (), diag::types_not_equal, ownerType, lhs, rhs);
781
- return true ;
782
- }
783
-
784
- default :
785
- break ;
786
- }
787
-
788
- return false ;
789
- }
790
-
791
655
bool FailureDiagnosis::diagnoseGeneralConversionFailure (Constraint *constraint){
792
656
auto anchor = expr;
793
657
bool resolvedAnchorToExpr = false ;
@@ -965,9 +829,6 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
965
829
}
966
830
}
967
831
968
- if (diagnoseTypeRequirementFailure (CS, constraint))
969
- return true ;
970
-
971
832
diagnose (anchor->getLoc (), diag::types_not_convertible,
972
833
constraint->getKind () == ConstraintKind::Subtype,
973
834
fromType, toType)
0 commit comments