Skip to content

Commit 90f0edc

Browse files
committed
Need to check that the keypath decl is an AbstractStorageDecl instead of assuming it.
1 parent 0d68e6e commit 90f0edc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3900,8 +3900,11 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
39003900
if (!choices[i].isDecl()) {
39013901
return SolutionKind::Error;
39023902
}
3903+
auto storage = dyn_cast<AbstractStorageDecl>(choices[i].getDecl());
3904+
if (!storage) {
3905+
return SolutionKind::Error;
3906+
}
39033907

3904-
auto storage = cast<AbstractStorageDecl>(choices[i].getDecl());
39053908
if (!storage->isSettable(DC)) {
39063909
// A non-settable component makes the key path read-only, unless
39073910
// a reference-writable component shows up later.

test/expr/unary/keypath/keypath.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,20 @@ func sr6106() {
485485
}
486486
}
487487

488+
// SR-6744
489+
func sr6744() {
490+
struct ABC {
491+
let value: Int
492+
func value(adding i: Int) -> Int { return value + i }
493+
}
494+
495+
let abc = ABC(value: 0)
496+
func get<T>(for kp: KeyPath<ABC, T>) -> T {
497+
return abc[keyPath: kp]
498+
}
499+
_ = get(for: \.value)
500+
}
501+
488502
func testSyntaxErrors() { // expected-note{{}}
489503
_ = \. ; // expected-error{{expected member name following '.'}}
490504
_ = \.a ;

0 commit comments

Comments
 (0)