Skip to content

Commit cd0047a

Browse files
authored
Merge pull request #31434 from slavapestov/dynamic-stored-property-with-observers-fix-5.3
Sema: Fix crash with stored property that has on-demand 'modify' accessor [5.3]
2 parents c61dccc + 9b1b2b3 commit cd0047a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,16 @@ synthesizeCoroutineAccessorBody(AccessorDecl *accessor, ASTContext &ctx) {
17641764

17651765
bool isModify = accessor->getAccessorKind() == AccessorKind::Modify;
17661766

1767+
// Special-case for a modify coroutine of a simple stored property with
1768+
// observers. We can yield a borrowed copy of the underlying storage
1769+
// in this case. However, if the accessor was synthesized on-demand,
1770+
// we do the more general thing, because on-demand accessors might be
1771+
// serialized, which prevents them from being able to directly reference
1772+
// didSet/willSet accessors, which are private.
17671773
if (isModify &&
17681774
(storageReadWriteImpl == ReadWriteImplKind::StoredWithSimpleDidSet ||
1769-
storageReadWriteImpl == ReadWriteImplKind::InheritedWithSimpleDidSet)) {
1775+
storageReadWriteImpl == ReadWriteImplKind::InheritedWithSimpleDidSet) &&
1776+
!accessor->hasForcedStaticDispatch()) {
17701777
return synthesizeModifyCoroutineBodyWithSimpleDidSet(accessor, ctx);
17711778
}
17721779

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
public protocol Proto {
5+
var property: Int { get set }
6+
}
7+
8+
public class ClassWithDynamicObservedProperty : Proto {
9+
@objc public dynamic var property: Int = 0 {
10+
didSet {}
11+
}
12+
}
13+
14+
// CHECK-LABEL: sil shared [serialized] [ossa] @$s40observers_with_on_demand_modify_accessor32ClassWithDynamicObservedPropertyC8propertySivM : $@yield_once @convention(method) (@guaranteed ClassWithDynamicObservedProperty) -> @yields @inout Int {
15+
// CHECK: objc_method %0 : $ClassWithDynamicObservedProperty, #ClassWithDynamicObservedProperty.property!getter.foreign
16+
// CHECK: objc_method %0 : $ClassWithDynamicObservedProperty, #ClassWithDynamicObservedProperty.property!setter.foreign
17+
// CHECK: return

0 commit comments

Comments
 (0)