Skip to content

Commit dddb4dc

Browse files
authored
Merge pull request #60732 from xedin/issue-60649-5.7
[5.7][CSSimplify] Failure to bind type variable to invalid dependent membe…
2 parents d08d898 + b5c843b commit dddb4dc

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
@@ -3856,6 +3856,13 @@ ConstraintSystem::matchTypesBindTypeVar(
38563856
// let's ignore this mismatch and mark affected type variable as a hole
38573857
// because something else has to be fixed already for this to happen.
38583858
if (type->is<DependentMemberType>() && !type->hasTypeVariable()) {
3859+
// Since the binding couldn't be performed, the type variable is a
3860+
// hole regardless whether it would be bound later to some other
3861+
// type or not. If this is not reflected in constraint system
3862+
// it would let the solver to form a _valid_ solution as if the
3863+
// constraint between the type variable and the unresolved dependent
3864+
// member type never existed.
3865+
increaseScore(SK_Hole);
38593866
recordPotentialHole(typeVar);
38603867
return getTypeMatchSuccess();
38613868
}
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)