Skip to content

Commit 636dfd6

Browse files
committed
[PropertyWrappers] lvalue computation in buildStorageReference() should use PropertyWrapperMutability
1 parent ecf76c8 commit 636dfd6

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,12 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
738738

739739
// If we're acessing a property wrapper, determine if the
740740
// intermediate access requires an lvalue.
741-
if (underlyingVars.size() > 0) {
742-
isMemberLValue = underlyingVars[0]->isGetterMutating();
743-
if (isLValue)
744-
isMemberLValue |= underlyingVars[0]->isSetterMutating();
741+
if (auto var = dyn_cast<VarDecl>(accessor->getStorage())) {
742+
if (auto mut = var->getPropertyWrapperMutability()) {
743+
isMemberLValue = mut->Getter == PropertyWrapperMutability::Mutating;
744+
if (isLValue)
745+
isMemberLValue |= mut->Setter == PropertyWrapperMutability::Mutating;
746+
}
745747
}
746748

747749
bool isSelfLValue = storage->isGetterMutating();

test/SILGen/property_wrappers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,30 @@ extension UsesMyPublished {
519519
}
520520
}
521521

522+
// SR-11603 - crash due to incorrect lvalue computation
523+
@propertyWrapper
524+
struct StructWrapper<T> {
525+
var wrappedValue: T
526+
}
527+
528+
@propertyWrapper
529+
class ClassWrapper<T> {
530+
var wrappedValue: T
531+
init(wrappedValue: T) {
532+
self.wrappedValue = wrappedValue
533+
}
534+
}
535+
536+
537+
struct SR_11603 {
538+
// CHECK: @StructWrapper @ClassWrapper var prop: Int { get nonmutating set }
539+
@StructWrapper @ClassWrapper var prop: Int
540+
541+
func foo() {
542+
prop = 1234
543+
}
544+
}
545+
522546
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
523547
// CHECK-NEXT: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
524548
// CHECK-NEXT: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s17property_wrappers17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter

0 commit comments

Comments
 (0)