Skip to content

Commit 9468edd

Browse files
committed
[SE-0258] Make sure we add accessors to backing storage in classes.
Thanks to Avi on the Swift Forums for pointing this out!
1 parent 8d1fabd commit 9468edd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,9 @@ void swift::maybeAddAccessorsToStorage(AbstractStorageDecl *storage) {
19731973
return;
19741974

19751975
// Implicit properties don't get accessors.
1976-
if (storage->isImplicit())
1976+
if (storage->isImplicit() &&
1977+
!(isa<VarDecl>(storage) &&
1978+
cast<VarDecl>(storage)->getOriginalDelegatedProperty()))
19771979
return;
19781980

19791981
if (!dc->isTypeContext()) {

test/SILGen/property_delegates.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,25 @@ struct UseStatic {
253253
// CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvsZ
254254
@Lazy static var staticWibble = [1, 2, 3]
255255
}
256+
257+
extension WrapperWithInitialValue {
258+
func test() { }
259+
}
260+
261+
class ClassUsingWrapper {
262+
@WrapperWithInitialValue var x = 0
263+
}
264+
265+
// CHECK-LABEL: sil hidden [ossa] @$s18property_delegates21testClassUsingWrapper1cyAA0deF0C_tF : $@convention(thin) (@guaranteed ClassUsingWrapper) -> ()
266+
func testClassUsingWrapper(c: ClassUsingWrapper) {
267+
// CHECK: class_method [[GETTER:%.*]] : $ClassUsingWrapper, #ClassUsingWrapper.$x!getter.1
268+
c.$x.test()
269+
}
270+
271+
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
272+
// CHECK: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s18property_delegates17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
273+
// CHECK: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s18property_delegates17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter
274+
// CHECK: #ClassUsingWrapper.x!modify.1: (ClassUsingWrapper) -> () -> () : @$s18property_delegates17ClassUsingWrapperC1xSivM // ClassUsingWrapper.x.modify
275+
// CHECK: #ClassUsingWrapper.$x!getter.1: (ClassUsingWrapper) -> () -> WrapperWithInitialValue<Int> : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvg // ClassUsingWrapper.$x.getter
276+
// CHECK: #ClassUsingWrapper.$x!setter.1: (ClassUsingWrapper) -> (WrapperWithInitialValue<Int>) -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvs // ClassUsingWrapper.$x.setter
277+
// CHECK: #ClassUsingWrapper.$x!modify.1: (ClassUsingWrapper) -> () -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvM // ClassUsingWrapper.$x.modify

0 commit comments

Comments
 (0)