Skip to content

Commit 0af4182

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 797a057 commit 0af4182

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
@@ -1833,6 +1833,13 @@ static void lookupConcreteNestedType(NominalTypeDecl *decl,
18331833
concreteDecls.push_back(cast<TypeDecl>(member));
18341834
}
18351835

1836+
static auto findBestConcreteNestedType(SmallVectorImpl<TypeDecl *> &concreteDecls) {
1837+
return std::min_element(concreteDecls.begin(), concreteDecls.end(),
1838+
[](TypeDecl *type1, TypeDecl *type2) {
1839+
return TypeDecl::compare(type1, type2) < 0;
1840+
});
1841+
}
1842+
18361843
TypeDecl *EquivalenceClass::lookupNestedType(
18371844
GenericSignatureBuilder &builder,
18381845
Identifier name,
@@ -1940,11 +1947,7 @@ TypeDecl *EquivalenceClass::lookupNestedType(
19401947
"Lookup should never keep a non-anchor associated type");
19411948
} else if (!concreteDecls.empty()) {
19421949
// Find the best concrete type.
1943-
auto bestConcreteTypeIter =
1944-
std::min_element(concreteDecls.begin(), concreteDecls.end(),
1945-
[](TypeDecl *type1, TypeDecl *type2) {
1946-
return TypeDecl::compare(type1, type2) < 0;
1947-
});
1950+
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
19481951

19491952
// Put the best concrete type first; the rest will follow.
19501953
entry.types.push_back(*bestConcreteTypeIter);
@@ -3559,7 +3562,8 @@ static Type getStructuralType(TypeDecl *typeDecl, bool keepSugar) {
35593562

35603563
static Type substituteConcreteType(Type parentType,
35613564
TypeDecl *concreteDecl) {
3562-
if (parentType->is<ErrorType>())
3565+
if (parentType->is<ErrorType>() ||
3566+
parentType->is<UnresolvedType>())
35633567
return parentType;
35643568

35653569
auto *dc = concreteDecl->getDeclContext();
@@ -3612,18 +3616,14 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
36123616
if (concreteDecls.empty())
36133617
return ResolvedType::forUnresolved(nullptr);
36143618

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-
3619+
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
36213620
concreteDecl = *bestConcreteTypeIter;
36223621
}
36233622
}
36243623

36253624
auto concreteType = substituteConcreteType(parentType, concreteDecl);
3626-
return ResolvedType::forConcrete(concreteType);
3625+
return maybeResolveEquivalenceClass(concreteType, resolutionKind,
3626+
wantExactPotentialArchetype);
36273627
}
36283628

36293629
// 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)