Skip to content

Commit 893318c

Browse files
committed
Fix the AccessStrategy for dynamic (not @objc) storage
It needs to be opaque but not dispatched.
1 parent f893a28 commit 893318c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ SourceRange IfConfigDecl::getSourceRange() const {
14161416
}
14171417

14181418
static bool isPolymorphic(const AbstractStorageDecl *storage) {
1419-
if (storage->isDynamic())
1419+
if (storage->isObjCDynamic())
14201420
return true;
14211421

14221422

@@ -1623,6 +1623,9 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
16231623
if (isPolymorphic(this))
16241624
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ true);
16251625

1626+
if (isDynamic())
1627+
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ false);
1628+
16261629
// If the storage is resilient to the given use DC (perhaps because
16271630
// it's @_transparent and we have to be careful about it being inlined
16281631
// across module lines), we cannot use direct access.

test/SILGen/keypath_dynamic.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen -enable-sil-ownership -module-name A %s | %FileCheck %s
2+
3+
struct Foo {
4+
var x : Int {
5+
get {
6+
return 1
7+
}
8+
set {
9+
}
10+
}
11+
12+
func foo(_ kp: WritableKeyPath<Foo, Int>) {
13+
}
14+
15+
func test() {
16+
// CHECK: keypath $WritableKeyPath<Foo, Int>, (root $Foo; settable_property $Int, id @$s1A3FooV1xSivg
17+
foo(\.x)
18+
}
19+
}

0 commit comments

Comments
 (0)