@@ -1809,6 +1809,18 @@ static int compareAssociatedTypes(AssociatedTypeDecl *assocType1,
1809
1809
return 0 ;
1810
1810
}
1811
1811
1812
+ static void lookupConcreteNestedType (NominalTypeDecl *decl,
1813
+ Identifier name,
1814
+ SmallVectorImpl<TypeDecl *> &concreteDecls) {
1815
+ SmallVector<ValueDecl *, 2 > foundMembers;
1816
+ decl->getParentModule ()->lookupQualified (
1817
+ decl, DeclNameRef (name),
1818
+ NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers,
1819
+ foundMembers);
1820
+ for (auto member : foundMembers)
1821
+ concreteDecls.push_back (cast<TypeDecl>(member));
1822
+ }
1823
+
1812
1824
TypeDecl *EquivalenceClass::lookupNestedType (
1813
1825
GenericSignatureBuilder &builder,
1814
1826
Identifier name,
@@ -1881,19 +1893,9 @@ TypeDecl *EquivalenceClass::lookupNestedType(
1881
1893
// FIXME: Shouldn't we always look here?
1882
1894
if (!bestAssocType && concreteDecls.empty ()) {
1883
1895
Type typeToSearch = concreteType ? concreteType : superclass;
1884
- auto *decl = typeToSearch ? typeToSearch->getAnyNominal () : nullptr ;
1885
- if (decl) {
1886
- SmallVector<ValueDecl *, 2 > foundMembers;
1887
- decl->getParentModule ()->lookupQualified (
1888
- decl, DeclNameRef (name),
1889
- NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers,
1890
- foundMembers);
1891
- for (auto member : foundMembers) {
1892
- if (auto type = dyn_cast<TypeDecl>(member)) {
1893
- concreteDecls.push_back (type);
1894
- }
1895
- }
1896
- }
1896
+ if (typeToSearch)
1897
+ if (auto *decl = typeToSearch->getAnyNominal ())
1898
+ lookupConcreteNestedType (decl, name, concreteDecls);
1897
1899
}
1898
1900
1899
1901
// Infer same-type constraints among same-named associated type anchors.
@@ -3531,8 +3533,6 @@ static Type substituteConcreteType(Type parentType,
3531
3533
if (parentType->is <ErrorType>())
3532
3534
return parentType;
3533
3535
3534
- assert (concreteDecl);
3535
-
3536
3536
auto *dc = concreteDecl->getDeclContext ();
3537
3537
3538
3538
// Form an unsubstituted type referring to the given type declaration,
@@ -3569,10 +3569,31 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
3569
3569
resolutionKind,
3570
3570
wantExactPotentialArchetype);
3571
3571
if (!resolvedBase) return resolvedBase;
3572
+
3572
3573
// If the base is concrete, so is this member.
3573
3574
if (auto parentType = resolvedBase.getAsConcreteType ()) {
3574
- auto concreteType = substituteConcreteType (parentType,
3575
- depMemTy->getAssocType ());
3575
+ TypeDecl *concreteDecl = depMemTy->getAssocType ();
3576
+ if (!concreteDecl) {
3577
+ // If we have an unresolved dependent member type, perform a
3578
+ // name lookup.
3579
+ if (auto *decl = parentType->getAnyNominal ()) {
3580
+ SmallVector<TypeDecl *, 2 > concreteDecls;
3581
+ lookupConcreteNestedType (decl, depMemTy->getName (), concreteDecls);
3582
+
3583
+ if (concreteDecls.empty ())
3584
+ return ResolvedType::forUnresolved (nullptr );
3585
+
3586
+ auto bestConcreteTypeIter =
3587
+ std::min_element (concreteDecls.begin (), concreteDecls.end (),
3588
+ [](TypeDecl *type1, TypeDecl *type2) {
3589
+ return TypeDecl::compare (type1, type2) < 0 ;
3590
+ });
3591
+
3592
+ concreteDecl = *bestConcreteTypeIter;
3593
+ }
3594
+ }
3595
+
3596
+ auto concreteType = substituteConcreteType (parentType, concreteDecl);
3576
3597
return ResolvedType::forConcrete (concreteType);
3577
3598
}
3578
3599
0 commit comments