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