Skip to content

Commit 026374f

Browse files
authored
Merge pull request swiftlang#24883 from slavapestov/unresolved-type-badness
AST: Fix crash when calling subst() on types involving member types of UnresolvedType
2 parents 5467232 + d80b554 commit 026374f

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/AST/Type.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,8 +2932,11 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
29322932
}
29332933

29342934
// If the parent is a type variable or a member rooted in a type variable,
2935-
// we're done.
2936-
if (substBase->isTypeVariableOrMember())
2935+
// or if the parent is a type parameter, we're done. Also handle
2936+
// UnresolvedType here, which can come up in diagnostics.
2937+
if (substBase->isTypeVariableOrMember() ||
2938+
substBase->isTypeParameter() ||
2939+
substBase->is<UnresolvedType>())
29372940
return getDependentMemberType(substBase);
29382941

29392942
// Retrieve the member type with the given name.
@@ -2942,10 +2945,6 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
29422945
if (substBase->is<TupleType>())
29432946
return failed();
29442947

2945-
// If the parent is dependent, create a dependent member type.
2946-
if (substBase->isTypeParameter())
2947-
return getDependentMemberType(substBase);
2948-
29492948
// If we know the associated type, look in the witness table.
29502949
LazyResolver *resolver = substBase->getASTContext().getLazyResolver();
29512950
if (assocType) {

test/Constraints/sr10595.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s
2+
3+
protocol Nested {
4+
associatedtype U // expected-note {{protocol requires nested type 'U'; do you want to add it?}}
5+
}
6+
7+
class A<M> {
8+
func f<T : Nested>(_ t: T, _ keyPath: WritableKeyPath<M, T.U>) {}
9+
}
10+
11+
class B<Y> : Nested { // expected-error {{type 'B<Y>' does not conform to protocol 'Nested'}}
12+
var i: Y?
13+
}
14+
15+
16+
class C<M> {
17+
func cFunc(_ a: A<M>) {
18+
let function: (B<Int>, ReferenceWritableKeyPath<M, Int>) -> Void = a.f // expected-error {{cannot convert value of type '(_, WritableKeyPath<M, _.U>) -> ()' to specified type '(B<Int>, ReferenceWritableKeyPath<M, Int>) -> Void'}}
19+
}
20+
}

0 commit comments

Comments
 (0)