Skip to content

Commit 4d03968

Browse files
committed
[CSSimplify] Failure to bind type variable to invalid dependent member makes it a hole
If the failure is not reflected in constraint system it would let the solver to form a _valid_ solution as if the constraint between the type variable and the unresolved dependent member type never existed. Resolves: #60649
1 parent dc38375 commit 4d03968

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,6 +3814,13 @@ ConstraintSystem::matchTypesBindTypeVar(
38143814
// let's ignore this mismatch and mark affected type variable as a hole
38153815
// because something else has to be fixed already for this to happen.
38163816
if (type->is<DependentMemberType>() && !type->hasTypeVariable()) {
3817+
// Since the binding couldn't be performed, the type variable is a
3818+
// hole regardless whether it would be bound later to some other
3819+
// type or not. If this is not reflected in constraint system
3820+
// it would let the solver to form a _valid_ solution as if the
3821+
// constraint between the type variable and the unresolved dependent
3822+
// member type never existed.
3823+
increaseScore(SK_Hole);
38173824
recordPotentialHole(typeVar);
38183825
return getTypeMatchSuccess();
38193826
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {}
4+
5+
protocol Key {
6+
associatedtype A: P
7+
// expected-note@-1 {{unable to infer associated type 'A' for protocol 'Key'}}
8+
static var value: A { get }
9+
}
10+
11+
struct Values {
12+
subscript<K: Key>(type: K.Type) -> K.A {
13+
fatalError()
14+
}
15+
}
16+
17+
enum MyKey: Key { // expected-error {{type 'MyKey' does not conform to protocol 'Key'}}
18+
static let value = 1
19+
// expected-note@-1 {{candidate would match and infer 'A' = 'Int' if 'Int' conformed to 'P'}}
20+
}
21+
22+
extension Values {
23+
var myValue: Int {
24+
get { self[MyKey.self] }
25+
}
26+
}

0 commit comments

Comments
 (0)