From 9468eddc52efac93d044a289388e25ace6848760 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Wed, 29 May 2019 13:16:53 -0700 Subject: [PATCH] [SE-0258] Make sure we add accessors to backing storage in classes. Thanks to Avi on the Swift Forums for pointing this out! --- lib/Sema/CodeSynthesis.cpp | 4 +++- test/SILGen/property_delegates.swift | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Sema/CodeSynthesis.cpp b/lib/Sema/CodeSynthesis.cpp index d6ea9a0b6391a..ca9c3409e0032 100644 --- a/lib/Sema/CodeSynthesis.cpp +++ b/lib/Sema/CodeSynthesis.cpp @@ -1973,7 +1973,9 @@ void swift::maybeAddAccessorsToStorage(AbstractStorageDecl *storage) { return; // Implicit properties don't get accessors. - if (storage->isImplicit()) + if (storage->isImplicit() && + !(isa(storage) && + cast(storage)->getOriginalDelegatedProperty())) return; if (!dc->isTypeContext()) { diff --git a/test/SILGen/property_delegates.swift b/test/SILGen/property_delegates.swift index 24a0534aa084c..47d7a7e88a4c8 100644 --- a/test/SILGen/property_delegates.swift +++ b/test/SILGen/property_delegates.swift @@ -253,3 +253,25 @@ struct UseStatic { // CHECK: sil hidden [transparent] [ossa] @$s18property_delegates9UseStaticV12staticWibbleSaySiGvsZ @Lazy static var staticWibble = [1, 2, 3] } + +extension WrapperWithInitialValue { + func test() { } +} + +class ClassUsingWrapper { + @WrapperWithInitialValue var x = 0 +} + +// CHECK-LABEL: sil hidden [ossa] @$s18property_delegates21testClassUsingWrapper1cyAA0deF0C_tF : $@convention(thin) (@guaranteed ClassUsingWrapper) -> () +func testClassUsingWrapper(c: ClassUsingWrapper) { + // CHECK: class_method [[GETTER:%.*]] : $ClassUsingWrapper, #ClassUsingWrapper.$x!getter.1 + c.$x.test() +} + +// CHECK-LABEL: sil_vtable ClassUsingWrapper { +// CHECK: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s18property_delegates17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter +// CHECK: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s18property_delegates17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter +// CHECK: #ClassUsingWrapper.x!modify.1: (ClassUsingWrapper) -> () -> () : @$s18property_delegates17ClassUsingWrapperC1xSivM // ClassUsingWrapper.x.modify +// CHECK: #ClassUsingWrapper.$x!getter.1: (ClassUsingWrapper) -> () -> WrapperWithInitialValue : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvg // ClassUsingWrapper.$x.getter +// CHECK: #ClassUsingWrapper.$x!setter.1: (ClassUsingWrapper) -> (WrapperWithInitialValue) -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvs // ClassUsingWrapper.$x.setter +// CHECK: #ClassUsingWrapper.$x!modify.1: (ClassUsingWrapper) -> () -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvM // ClassUsingWrapper.$x.modify