@@ -415,7 +415,9 @@ static void lookupDeclsFromProtocolsBeingConformedTo(
415
415
}
416
416
417
417
DeclVisibilityKind ReasonForThisProtocol;
418
- if (Reason == DeclVisibilityKind::MemberOfCurrentNominal)
418
+ if (Conformance->getKind () == ProtocolConformanceKind::Inherited)
419
+ ReasonForThisProtocol = getReasonForSuper (Reason);
420
+ else if (Reason == DeclVisibilityKind::MemberOfCurrentNominal)
419
421
ReasonForThisProtocol =
420
422
DeclVisibilityKind::MemberOfProtocolImplementedByCurrentNominal;
421
423
else
@@ -629,50 +631,66 @@ static void lookupVisibleMemberDeclsImpl(
629
631
}
630
632
}
631
633
632
- llvm::SmallPtrSet<ClassDecl *, 8 > Ancestors;
633
- do {
634
- NominalTypeDecl *CurNominal = BaseTy->getAnyNominal ();
635
- if (!CurNominal)
636
- break ;
637
-
638
- synthesizeMemberDeclsForLookup (CurNominal, CurrDC);
634
+ const auto synthesizeAndLookupTypeMembers = [&](NominalTypeDecl *NTD) {
635
+ synthesizeMemberDeclsForLookup (NTD, CurrDC);
639
636
640
637
// Look in for members of a nominal type.
641
638
lookupTypeMembers (BaseTy, BaseTy, Consumer, CurrDC, LS, Reason);
639
+ };
640
+
641
+ llvm::SmallPtrSet<ClassDecl *, 8 > Ancestors;
642
+ {
643
+ const auto NTD = BaseTy->getAnyNominal ();
644
+ if (NTD == nullptr )
645
+ return ;
646
+
647
+ synthesizeAndLookupTypeMembers (NTD);
642
648
lookupDeclsFromProtocolsBeingConformedTo (BaseTy, Consumer, LS, CurrDC,
643
649
Reason, Visited);
644
- // If we have a class type, look into its superclass.
645
- auto *CurClass = dyn_cast<ClassDecl>(CurNominal);
646
650
651
+ const auto CD = dyn_cast<ClassDecl>(NTD);
647
652
// FIXME: We check `getSuperclass()` here because we'll be using the
648
653
// superclass Type below, and in ill-formed code `hasSuperclass()` could
649
654
// be true while `getSuperclass()` returns null, because the latter
650
655
// looks for a declaration.
651
- if (CurClass && CurClass->getSuperclass ()) {
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 {
669
+ return ;
670
+ }
671
+ }
672
+
673
+ // 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 ()) {
652
678
// FIXME: This path is no substitute for an actual circularity check.
653
679
// The real fix is to check that the superclass doesn't introduce a
654
680
// circular reference before it's written into the AST.
655
681
if (Ancestors.count (CurClass)) {
656
682
break ;
657
683
}
684
+ Ancestors.insert (CurClass);
658
685
659
- BaseTy = CurClass->getSuperclass ();
660
- Reason = getReasonForSuper (Reason);
686
+ BaseTy = superclassTy;
661
687
662
- bool InheritsSuperclassInitializers =
663
- CurClass->inheritsSuperclassInitializers ();
664
- if (LS.isOnSuperclass () && !InheritsSuperclassInitializers)
688
+ if (!CurClass->inheritsSuperclassInitializers ())
665
689
LS = LS.withoutInheritsSuperclassInitializers ();
666
- else if (!LS.isOnSuperclass ()) {
667
- LS = LS.withOnSuperclass ();
668
- if (InheritsSuperclassInitializers)
669
- LS = LS.withInheritsSuperclassInitializers ();
670
- }
671
690
} else {
672
691
break ;
673
692
}
674
- Ancestors.insert (CurClass);
675
- } while (1 );
693
+ }
676
694
}
677
695
678
696
swift::DynamicLookupInfo::DynamicLookupInfo (
0 commit comments