Skip to content

Commit 96dc765

Browse files
committed
SILGen: Don't emit key path descriptors for properties with mutating getters
Fixes <https://bugs.swift.org/browse/SR-7176>, <rdar://problem/38439418>.
1 parent 4eb495d commit 96dc765

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,10 @@ static bool doesPropertyNeedDescriptor(AbstractStorageDecl *decl) {
11721172
if (!decl->getGetter())
11731173
return false;
11741174

1175+
// If the getter is mutating, we cannot form a keypath to it at all.
1176+
if (decl->isGetterMutating())
1177+
return false;
1178+
11751179
// TODO: If previous versions of an ABI-stable binary needed the descriptor,
11761180
// then we still do.
11771181

test/SILGen/keypath_property_descriptors.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,18 @@ public struct A {
7676
internal subscript<T>(d x: T) -> T { return x }
7777
fileprivate subscript<T>(e x: T) -> T { return x }
7878
private subscript<T>(f x: T) -> T { return x }
79+
80+
// no descriptor
81+
public var count: Int {
82+
mutating get {
83+
_count += 1
84+
return _count
85+
}
86+
set {
87+
_count = newValue
88+
}
89+
}
90+
91+
private var _count: Int = 0
7992
}
8093

0 commit comments

Comments
 (0)