Skip to content

Commit 38815ec

Browse files
committed
SILGen: Fix crash on assignment to static property wrapper through 'self'
Fixes <rdar://problem/59117087>.
1 parent 1d2d8d4 commit 38815ec

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,9 @@ namespace {
13841384
assert(getAccessorDecl()->isSetter());
13851385
SILDeclRef setter = Accessor;
13861386

1387-
if (hasPropertyWrapper() && IsOnSelfParameter &&
1387+
if (IsOnSelfParameter &&
1388+
!Storage->isStatic() &&
1389+
hasPropertyWrapper() &&
13881390
isBackingVarVisible(cast<VarDecl>(Storage),
13891391
SGF.FunctionDC)) {
13901392
// This is wrapped property. Instead of emitting a setter, emit an

test/SILGen/property_wrappers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,21 @@ struct WrappedIntContainer {
569569
@WrappedInt var int: Int?
570570
}
571571

572+
// rdar://problem/59117087 - crash due to incorrectly taking the "self access"
573+
// path for a static property with a wrapper
574+
575+
struct HasStaticWrapper {
576+
@StructWrapper static var staticWrapper: Int = 0
577+
578+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers16HasStaticWrapperV08assignToD4SelfyyFZ : $@convention(method) (@thin HasStaticWrapper.Type) -> () {
579+
static func assignToStaticSelf() {
580+
// Make sure we call the setter instead of attempting a direct access,
581+
// like we would if the property was not static:
582+
583+
// CHECK: function_ref @$s17property_wrappers16HasStaticWrapperV06staticE0SivsZ : $@convention(method) (Int, @thin HasStaticWrapper.Type) -> ()
584+
staticWrapper = 1
585+
}
586+
}
572587

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

0 commit comments

Comments
 (0)