Skip to content

Commit 034c2be

Browse files
committed
GSB: An unresolved DependentMemberType might resolve to a concrete TypeAliasDecl with a dependent underlying type
Fixes https://bugs.swift.org/browse/SR-11639 / rdar://problem/56466696
1 parent 3a9ddf2 commit 034c2be

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,13 @@ static void lookupConcreteNestedType(NominalTypeDecl *decl,
18211821
concreteDecls.push_back(cast<TypeDecl>(member));
18221822
}
18231823

1824+
static auto findBestConcreteNestedType(SmallVectorImpl<TypeDecl *> &concreteDecls) {
1825+
return std::min_element(concreteDecls.begin(), concreteDecls.end(),
1826+
[](TypeDecl *type1, TypeDecl *type2) {
1827+
return TypeDecl::compare(type1, type2) < 0;
1828+
});
1829+
}
1830+
18241831
TypeDecl *EquivalenceClass::lookupNestedType(
18251832
GenericSignatureBuilder &builder,
18261833
Identifier name,
@@ -1928,11 +1935,7 @@ TypeDecl *EquivalenceClass::lookupNestedType(
19281935
"Lookup should never keep a non-anchor associated type");
19291936
} else if (!concreteDecls.empty()) {
19301937
// Find the best concrete type.
1931-
auto bestConcreteTypeIter =
1932-
std::min_element(concreteDecls.begin(), concreteDecls.end(),
1933-
[](TypeDecl *type1, TypeDecl *type2) {
1934-
return TypeDecl::compare(type1, type2) < 0;
1935-
});
1938+
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
19361939

19371940
// Put the best concrete type first; the rest will follow.
19381941
entry.types.push_back(*bestConcreteTypeIter);
@@ -3530,7 +3533,8 @@ static Type getStructuralType(TypeDecl *typeDecl, bool keepSugar) {
35303533

35313534
static Type substituteConcreteType(Type parentType,
35323535
TypeDecl *concreteDecl) {
3533-
if (parentType->is<ErrorType>())
3536+
if (parentType->is<ErrorType>() ||
3537+
parentType->is<UnresolvedType>())
35343538
return parentType;
35353539

35363540
auto *dc = concreteDecl->getDeclContext();
@@ -3583,18 +3587,14 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
35833587
if (concreteDecls.empty())
35843588
return ResolvedType::forUnresolved(nullptr);
35853589

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-
3590+
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
35923591
concreteDecl = *bestConcreteTypeIter;
35933592
}
35943593
}
35953594

35963595
auto concreteType = substituteConcreteType(parentType, concreteDecl);
3597-
return ResolvedType::forConcrete(concreteType);
3596+
return maybeResolveEquivalenceClass(concreteType, resolutionKind,
3597+
wantExactPotentialArchetype);
35983598
}
35993599

36003600
// Find the nested type declaration for this.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s
2+
3+
public protocol FooProtocol {
4+
associatedtype Bar
5+
}
6+
7+
public struct Foo<Bar>: FooProtocol {
8+
public var bar: Bar
9+
}
10+
11+
public protocol BazProtocol: FooProtocol {
12+
associatedtype Foo1: FooProtocol where Foo1.Bar == Foo2.Bar
13+
associatedtype Foo2Bar
14+
typealias Foo2 = Foo<Foo2Bar>
15+
}

0 commit comments

Comments
 (0)