@@ -590,6 +590,14 @@ SelfBoundsFromWhereClauseRequest::evaluate(
590
590
auto *extDecl = decl.dyn_cast <ExtensionDecl *>();
591
591
592
592
DeclContext *dc = protoDecl ? (DeclContext *)protoDecl : (DeclContext *)extDecl;
593
+
594
+ // A protocol or extension 'where' clause can reference associated types of
595
+ // the protocol itself, so we have to start unqualified lookup from 'dc'.
596
+ //
597
+ // However, the right hand side of a 'Self' conformance constraint must be
598
+ // resolved before unqualified lookup into 'dc' can work, so we make an
599
+ // exception here and begin lookup from the parent context instead.
600
+ auto *lookupDC = dc->getParent ();
593
601
auto requirements = protoDecl ? protoDecl->getTrailingWhereClause ()
594
602
: extDecl->getTrailingWhereClause ();
595
603
@@ -619,7 +627,7 @@ SelfBoundsFromWhereClauseRequest::evaluate(
619
627
// Resolve the right-hand side.
620
628
DirectlyReferencedTypeDecls rhsDecls;
621
629
if (auto typeRepr = req.getConstraintRepr ()) {
622
- rhsDecls = directReferencesForTypeRepr (evaluator, ctx, typeRepr, dc );
630
+ rhsDecls = directReferencesForTypeRepr (evaluator, ctx, typeRepr, lookupDC );
623
631
} else if (Type type = req.getConstraint ()) {
624
632
rhsDecls = directReferencesForType (type);
625
633
}
0 commit comments