Skip to content

Commit a648714

Browse files
Merge pull request swiftlang#26410 from aschwaighofer/property_wrapper_storage_wrapper_backing_var_access_visibility
Sema: Don't mark the accessors of the storage wrapper transparent if its backing var has lower visibility than the var
2 parents 5177b96 + 090b740 commit a648714

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ static void maybeMarkTransparent(AccessorDecl *accessor, ASTContext &ctx) {
352352

353353
if (auto original = var->getOriginalWrappedProperty(
354354
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
355-
if (var->getFormalAccess() < original->getFormalAccess())
355+
auto backingVar = original->getPropertyWrapperBackingProperty();
356+
if (backingVar->getFormalAccess() < var->getFormalAccess())
356357
return;
357358
}
358359
}

test/SILGen/property_wrappers.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct WrapperWithStorageValue<T> {
191191

192192
struct UseWrapperWithStorageValue {
193193
// UseWrapperWithStorageValue._x.getter
194-
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s17property_wrappers26UseWrapperWithStorageValueV2$xAA0D0VySiGvg : $@convention(method) (UseWrapperWithStorageValue) -> Wrapper<Int>
194+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers26UseWrapperWithStorageValueV2$xAA0D0VySiGvg : $@convention(method) (UseWrapperWithStorageValue) -> Wrapper<Int>
195195
// CHECK-NOT: return
196196
// CHECK: function_ref @$s17property_wrappers23WrapperWithStorageValueV09projectedF0AA0C0VyxGvg
197197
@WrapperWithStorageValue(wrappedValue: 17) var x: Int
@@ -408,7 +408,44 @@ class TestResilientDI {
408408
}
409409
}
410410

411+
@propertyWrapper
412+
public struct PublicWrapper<T> {
413+
public var wrappedValue: T
414+
415+
public init(value: T) {
416+
wrappedValue = value
417+
}
418+
}
419+
420+
@propertyWrapper
421+
public struct PublicWrapperWithStorageValue<T> {
422+
public var wrappedValue: T
423+
424+
public init(wrappedValue: T) {
425+
self.wrappedValue = wrappedValue
426+
}
427+
428+
public var projectedValue: PublicWrapper<T> {
429+
return PublicWrapper(value: wrappedValue)
430+
}
431+
}
411432

433+
public class Container {
434+
public init() {
435+
}
436+
437+
// The accessor cannot be serializable/transparent because it accesses an
438+
// internal var.
439+
// CHECK-LABEL: sil [ossa] @$s17property_wrappers9ContainerC10$dontCrashAA13PublicWrapperVySiGvg : $@convention(method) (@guaranteed Container) -> PublicWrapper<Int> {
440+
// CHECK: bb0(%0 : @guaranteed $Container):
441+
// CHECK: ref_element_addr %0 : $Container, #Container._dontCrash
442+
@PublicWrapperWithStorageValue(wrappedValue: 0) public var dontCrash : Int {
443+
willSet {
444+
}
445+
didSet {
446+
}
447+
}
448+
}
412449

413450
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
414451
// CHECK-NEXT: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter

0 commit comments

Comments
 (0)