@@ -6614,45 +6614,50 @@ bool ProtocolDecl::inheritsFrom(const ProtocolDecl *super) const {
6614
6614
});
6615
6615
}
6616
6616
6617
- static bool hasInverseMarking (ProtocolDecl *P, InvertibleProtocolKind target) {
6618
- auto &ctx = P->getASTContext ();
6617
+ std::pair</* found=*/ bool , /* where=*/ SourceLoc>
6618
+ ProtocolDecl::hasInverseMarking (InvertibleProtocolKind target) const {
6619
+ auto &ctx = getASTContext ();
6619
6620
6620
6621
// Legacy support stops here.
6621
6622
if (!ctx.LangOpts .hasFeature (Feature::NoncopyableGenerics))
6622
- return false ;
6623
+ return std::make_pair ( false , SourceLoc ()) ;
6623
6624
6624
- auto inheritedTypes = P-> getInherited ();
6625
+ auto inheritedTypes = getInherited ();
6625
6626
for (unsigned i = 0 ; i < inheritedTypes.size (); ++i) {
6626
- auto type = inheritedTypes.getResolvedType (i, TypeResolutionStage::Structural);
6627
+ auto type =
6628
+ inheritedTypes.getResolvedType (i, TypeResolutionStage::Structural);
6627
6629
if (!type)
6628
6630
continue ;
6629
6631
6632
+ auto *repr = inheritedTypes.getTypeRepr (i);
6633
+
6630
6634
if (auto *composition = type->getAs <ProtocolCompositionType>()) {
6631
6635
// Found ~<target> in the protocol inheritance clause.
6632
6636
if (composition->getInverses ().contains (target))
6633
- return true ;
6637
+ return std::make_pair ( true , repr ? repr-> getLoc () : SourceLoc ()) ;
6634
6638
}
6635
6639
}
6636
6640
6637
- auto *whereClause = P-> getTrailingWhereClause ();
6641
+ auto *whereClause = getTrailingWhereClause ();
6638
6642
if (!whereClause)
6639
- return false ;
6643
+ return std::make_pair ( false , SourceLoc ()) ;
6640
6644
6641
- return llvm::any_of (
6642
- whereClause->getRequirements (), [&](const RequirementRepr &reqRepr) {
6643
- if (reqRepr.isInvalid () ||
6644
- reqRepr.getKind () != RequirementReprKind::TypeConstraint)
6645
- return false ;
6645
+ for (const auto &reqRepr : whereClause->getRequirements ()) {
6646
+ if (reqRepr.isInvalid () ||
6647
+ reqRepr.getKind () != RequirementReprKind::TypeConstraint)
6648
+ continue ;
6646
6649
6647
- auto *subjectRepr = dyn_cast<IdentTypeRepr>(reqRepr.getSubjectRepr ());
6648
- auto *constraintRepr = reqRepr.getConstraintRepr ();
6650
+ auto *subjectRepr = dyn_cast<IdentTypeRepr>(reqRepr.getSubjectRepr ());
6651
+ auto *constraintRepr = reqRepr.getConstraintRepr ();
6649
6652
6650
- if (!subjectRepr ||
6651
- !subjectRepr->getNameRef ().isSimpleName (ctx.Id_Self ))
6652
- return false ;
6653
+ if (!subjectRepr || !subjectRepr->getNameRef ().isSimpleName (ctx.Id_Self ))
6654
+ continue ;
6653
6655
6654
- return constraintRepr->isInverseOf (target, P->getDeclContext ());
6655
- });
6656
+ if (constraintRepr->isInverseOf (target, getDeclContext ()))
6657
+ return std::make_pair (true , constraintRepr->getLoc ());
6658
+ }
6659
+
6660
+ return std::make_pair (false , SourceLoc ());
6656
6661
}
6657
6662
6658
6663
bool ProtocolDecl::requiresInvertible (InvertibleProtocolKind ip) const {
@@ -6684,7 +6689,7 @@ bool ProtocolDecl::requiresInvertible(InvertibleProtocolKind ip) const {
6684
6689
// Otherwise, check to see if there's an inverse on this protocol.
6685
6690
6686
6691
// The implicit requirement was suppressed on this protocol, keep looking.
6687
- if (hasInverseMarking (proto, ip))
6692
+ if (proto-> hasInverseMarking (ip). first )
6688
6693
return TypeWalker::Action::Continue;
6689
6694
6690
6695
return TypeWalker::Action::Stop; // No inverse, so implicitly inherited.
0 commit comments