Skip to content

Commit

Permalink
[SE-0258] Make sure we add accessors to backing storage in classes.
Browse files Browse the repository at this point in the history
Thanks to Avi on the Swift Forums for pointing this out!
  • Loading branch information
DougGregor committed May 29, 2019
1 parent 8d1fabd commit 9468edd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,9 @@ void swift::maybeAddAccessorsToStorage(AbstractStorageDecl *storage) {
return;

// Implicit properties don't get accessors.
if (storage->isImplicit())
if (storage->isImplicit() &&
!(isa<VarDecl>(storage) &&
cast<VarDecl>(storage)->getOriginalDelegatedProperty()))
return;

if (!dc->isTypeContext()) {
Expand Down
22 changes: 22 additions & 0 deletions test/SILGen/property_delegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int> : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvg // ClassUsingWrapper.$x.getter
// CHECK: #ClassUsingWrapper.$x!setter.1: (ClassUsingWrapper) -> (WrapperWithInitialValue<Int>) -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvs // ClassUsingWrapper.$x.setter
// CHECK: #ClassUsingWrapper.$x!modify.1: (ClassUsingWrapper) -> () -> () : @$s18property_delegates17ClassUsingWrapperC2$xAA0E16WithInitialValueVySiGvM // ClassUsingWrapper.$x.modify

0 comments on commit 9468edd

Please sign in to comment.