Skip to content

Commit be4ad49

Browse files
committed
Address suggestions
1 parent 137ef22 commit be4ad49

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -645,52 +645,47 @@ static void lookupVisibleMemberDeclsImpl(
645645
return;
646646

647647
synthesizeAndLookupTypeMembers(NTD);
648+
// Look into protocols only on the current nominal to avoid repeatedly
649+
// visiting inherited conformances.
648650
lookupDeclsFromProtocolsBeingConformedTo(BaseTy, Consumer, LS, CurrDC,
649651
Reason, Visited);
650652

651653
const auto CD = dyn_cast<ClassDecl>(NTD);
654+
652655
// FIXME: We check `getSuperclass()` here because we'll be using the
653656
// superclass Type below, and in ill-formed code `hasSuperclass()` could
654657
// be true while `getSuperclass()` returns null, because the latter
655658
// looks for a declaration.
656-
//
657-
// If we have a superclass, switch state and look into the
658-
// inheritance chain.
659-
if (CD && CD->getSuperclass()) {
660-
Ancestors.insert(CD);
661-
662-
Reason = getReasonForSuper(Reason);
663-
BaseTy = CD->getSuperclass();
664-
665-
LS = LS.withOnSuperclass();
666-
if (CD->inheritsSuperclassInitializers())
667-
LS = LS.withInheritsSuperclassInitializers();
668-
} else {
659+
if (!CD || !CD->getSuperclass())
669660
return;
670-
}
661+
662+
// We have a superclass; switch state and look into the inheritance chain.
663+
Ancestors.insert(CD);
664+
665+
Reason = getReasonForSuper(Reason);
666+
BaseTy = CD->getSuperclass();
667+
668+
LS = LS.withOnSuperclass();
669+
if (CD->inheritsSuperclassInitializers())
670+
LS = LS.withInheritsSuperclassInitializers();
671671
}
672672

673673
// Look into the inheritance chain.
674-
while (const auto CurClass = cast_or_null<ClassDecl>(
675-
BaseTy->getAnyNominal())) {
676-
synthesizeAndLookupTypeMembers(CurClass);
677-
if (const auto superclassTy = CurClass->getSuperclass()) {
678-
// FIXME: This path is no substitute for an actual circularity check.
679-
// The real fix is to check that the superclass doesn't introduce a
680-
// circular reference before it's written into the AST.
681-
if (Ancestors.count(CurClass)) {
682-
break;
683-
}
684-
Ancestors.insert(CurClass);
685-
686-
BaseTy = superclassTy;
674+
do {
675+
const auto CurClass = BaseTy->getClassOrBoundGenericClass();
687676

688-
if (!CurClass->inheritsSuperclassInitializers())
689-
LS = LS.withoutInheritsSuperclassInitializers();
690-
} else {
677+
// FIXME: This path is no substitute for an actual circularity check.
678+
// The real fix is to check that the superclass doesn't introduce a
679+
// circular reference before it's written into the AST.
680+
if (!Ancestors.insert(CurClass).second)
691681
break;
692-
}
693-
}
682+
683+
synthesizeAndLookupTypeMembers(CurClass);
684+
685+
BaseTy = CurClass->getSuperclass();
686+
if (!CurClass->inheritsSuperclassInitializers())
687+
LS = LS.withoutInheritsSuperclassInitializers();
688+
} while (BaseTy);
694689
}
695690

696691
swift::DynamicLookupInfo::DynamicLookupInfo(

0 commit comments

Comments
 (0)