Skip to content

Commit 148a3a5

Browse files
authored
Merge pull request #15250 from slavapestov/mutating-getter-keypath-problem-4.2
SILGen: Don't emit key path descriptors for properties with mutating getters [4.2]
2 parents d5a0d88 + 96dc765 commit 148a3a5

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)