Skip to content

Commit b99ccd3

Browse files
committed
[ConstraintSystem] Look through key path dynamic lookup nodes while simplifying locators
Key path dynamic member lookup should be completely transparent for simplification purposes, it's just a means to get to the current overload choice. Resolves: rdar://problem/62989214
1 parent 53055fa commit b99ccd3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,12 @@ void constraints::simplifyLocator(ASTNode &anchor,
35053505
continue;
35063506
}
35073507

3508+
case ConstraintLocator::KeyPathDynamicMember: {
3509+
// Key path dynamic member lookup should be completely transparent.
3510+
path = path.slice(1);
3511+
continue;
3512+
}
3513+
35083514
default:
35093515
// FIXME: Lots of other cases to handle.
35103516
break;

test/Constraints/diagnostics.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,3 +1483,24 @@ func rdar62428353<T>(_ t: inout T) {
14831483
let v = t // expected-note {{change 'let' to 'var' to make it mutable}} {{3-6=var}}
14841484
rdar62428353(v) // expected-error {{cannot pass immutable value as inout argument: 'v' is a 'let' constant}}
14851485
}
1486+
1487+
func rdar62989214() {
1488+
struct Flag {
1489+
var isTrue: Bool
1490+
}
1491+
1492+
@propertyWrapper @dynamicMemberLookup
1493+
struct Wrapper<Value> {
1494+
var wrappedValue: Value
1495+
1496+
subscript<Subject>(
1497+
dynamicMember keyPath: WritableKeyPath<Value, Subject>
1498+
) -> Wrapper<Subject> {
1499+
get { fatalError() }
1500+
}
1501+
}
1502+
1503+
func test(arr: Wrapper<[Flag]>, flag: Flag) {
1504+
arr[flag].isTrue // expected-error {{cannot convert value of type 'Flag' to expected argument type 'Int'}}
1505+
}
1506+
}

0 commit comments

Comments
 (0)