Skip to content

Commit 04453d1

Browse files
authored
Merge pull request #10810 from jckarter/keypath-apply-lvalue
Sema: Coerce [keyPath:] index to rvalue.
2 parents b8dc826 + a3c6dbc commit 04453d1

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ namespace {
13081308

13091309
// Apply a key path if we have one.
13101310
if (choice.getKind() == OverloadChoiceKind::KeyPathApplication) {
1311+
index = cs.coerceToRValue(index);
13111312
// The index argument should be (keyPath: KeyPath<Root, Value>).
13121313
auto keyPathTTy = cs.getType(index)->castTo<TupleType>()
13131314
->getElementType(0);

test/expr/unary/keypath/keypath.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ func testKeyPathSubscriptTuple(readonly: (Z,Z), writable: inout (Z,Z),
322322
writable[keyPath: rkp] = sink
323323
}
324324

325+
func testKeyPathSubscriptLValue(base: Z, kp: inout KeyPath<Z, Z>) {
326+
_ = base[keyPath: kp]
327+
}
328+
325329
struct AA {
326330
subscript(x: Int) -> Int { return x }
327331
var c: CC? = CC()

0 commit comments

Comments
 (0)