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