@@ -1821,6 +1821,18 @@ static int compareAssociatedTypes(AssociatedTypeDecl *assocType1,
1821
1821
return 0 ;
1822
1822
}
1823
1823
1824
+ static void lookupConcreteNestedType (NominalTypeDecl *decl,
1825
+ Identifier name,
1826
+ SmallVectorImpl<TypeDecl *> &concreteDecls) {
1827
+ SmallVector<ValueDecl *, 2 > foundMembers;
1828
+ decl->getParentModule ()->lookupQualified (
1829
+ decl, DeclNameRef (name),
1830
+ NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers,
1831
+ foundMembers);
1832
+ for (auto member : foundMembers)
1833
+ concreteDecls.push_back (cast<TypeDecl>(member));
1834
+ }
1835
+
1824
1836
TypeDecl *EquivalenceClass::lookupNestedType (
1825
1837
GenericSignatureBuilder &builder,
1826
1838
Identifier name,
@@ -1893,19 +1905,9 @@ TypeDecl *EquivalenceClass::lookupNestedType(
1893
1905
// FIXME: Shouldn't we always look here?
1894
1906
if (!bestAssocType && concreteDecls.empty ()) {
1895
1907
Type typeToSearch = concreteType ? concreteType : superclass;
1896
- auto *decl = typeToSearch ? typeToSearch->getAnyNominal () : nullptr ;
1897
- if (decl) {
1898
- SmallVector<ValueDecl *, 2 > foundMembers;
1899
- decl->getParentModule ()->lookupQualified (
1900
- decl, DeclNameRef (name),
1901
- NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers,
1902
- foundMembers);
1903
- for (auto member : foundMembers) {
1904
- if (auto type = dyn_cast<TypeDecl>(member)) {
1905
- concreteDecls.push_back (type);
1906
- }
1907
- }
1908
- }
1908
+ if (typeToSearch)
1909
+ if (auto *decl = typeToSearch->getAnyNominal ())
1910
+ lookupConcreteNestedType (decl, name, concreteDecls);
1909
1911
}
1910
1912
1911
1913
// Infer same-type constraints among same-named associated type anchors.
@@ -3560,8 +3562,6 @@ static Type substituteConcreteType(Type parentType,
3560
3562
if (parentType->is <ErrorType>())
3561
3563
return parentType;
3562
3564
3563
- assert (concreteDecl);
3564
-
3565
3565
auto *dc = concreteDecl->getDeclContext ();
3566
3566
3567
3567
// Form an unsubstituted type referring to the given type declaration,
@@ -3598,10 +3598,31 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
3598
3598
resolutionKind,
3599
3599
wantExactPotentialArchetype);
3600
3600
if (!resolvedBase) return resolvedBase;
3601
+
3601
3602
// If the base is concrete, so is this member.
3602
3603
if (auto parentType = resolvedBase.getAsConcreteType ()) {
3603
- auto concreteType = substituteConcreteType (parentType,
3604
- depMemTy->getAssocType ());
3604
+ TypeDecl *concreteDecl = depMemTy->getAssocType ();
3605
+ if (!concreteDecl) {
3606
+ // If we have an unresolved dependent member type, perform a
3607
+ // name lookup.
3608
+ if (auto *decl = parentType->getAnyNominal ()) {
3609
+ SmallVector<TypeDecl *, 2 > concreteDecls;
3610
+ lookupConcreteNestedType (decl, depMemTy->getName (), concreteDecls);
3611
+
3612
+ if (concreteDecls.empty ())
3613
+ return ResolvedType::forUnresolved (nullptr );
3614
+
3615
+ auto bestConcreteTypeIter =
3616
+ std::min_element (concreteDecls.begin (), concreteDecls.end (),
3617
+ [](TypeDecl *type1, TypeDecl *type2) {
3618
+ return TypeDecl::compare (type1, type2) < 0 ;
3619
+ });
3620
+
3621
+ concreteDecl = *bestConcreteTypeIter;
3622
+ }
3623
+ }
3624
+
3625
+ auto concreteType = substituteConcreteType (parentType, concreteDecl);
3605
3626
return ResolvedType::forConcrete (concreteType);
3606
3627
}
3607
3628
0 commit comments