Skip to content

Commit 314f044

Browse files
authored
Merge pull request #31655 from xedin/rdar-62989214-5.3
[5.3][ConstraintSystem] Look through key path dynamic lookup nodes while s…
2 parents 15956e4 + 0ac7c68 commit 314f044

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
@@ -3508,6 +3508,12 @@ void constraints::simplifyLocator(Expr *&anchor,
35083508
continue;
35093509
}
35103510

3511+
case ConstraintLocator::KeyPathDynamicMember: {
3512+
// Key path dynamic member lookup should be completely transparent.
3513+
path = path.slice(1);
3514+
continue;
3515+
}
3516+
35113517
default:
35123518
// FIXME: Lots of other cases to handle.
35133519
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)