Skip to content

Commit 150614f

Browse files
committed
[AST] InitAccessors: fallback to init accessor effects if @storageRestrictions is not used
(cherry picked from commit e84cd81)
1 parent 55dfdea commit 150614f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9529,15 +9529,27 @@ void AccessorDecl::printUserFacingName(raw_ostream &out) const {
95299529

95309530
ArrayRef<VarDecl *> AccessorDecl::getInitializedProperties() const {
95319531
assert(isInitAccessor());
9532+
95329533
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
95339534
return SR->getInitializesProperties(const_cast<AccessorDecl *>(this));
9535+
9536+
// Fallback to old effect style declaration.
9537+
if (auto *initAttr = getAttrs().getAttribute<InitializesAttr>())
9538+
return initAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));
9539+
95349540
return {};
95359541
}
95369542

95379543
ArrayRef<VarDecl *> AccessorDecl::getAccessedProperties() const {
95389544
assert(isInitAccessor());
9545+
95399546
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
95409547
return SR->getAccessesProperties(const_cast<AccessorDecl *>(this));
9548+
9549+
// Fallback to old effect style declaration.
9550+
if (auto *accessAttr = getAttrs().getAttribute<AccessesAttr>())
9551+
return accessAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));
9552+
95419553
return {};
95429554
}
95439555

test/Interpreter/init_accessors.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,25 @@ test_init_accessors_without_setters()
538538
// CHECK: test-without-setter1: 42
539539
// CHECK-NEXT: test-without-setter2: [1, 2, 3]
540540
// CHECK-NEXT: test-without-setter3: ["a", "b", "c"]
541+
542+
func test_effects_are_still_supported() {
543+
struct Test {
544+
var _a: Int
545+
var _b: Int
546+
547+
var a: Int {
548+
init(initialValue) initializes(_a) accesses(_b) {
549+
_a = initialValue
550+
_b = 0
551+
}
552+
553+
get { _a }
554+
}
555+
}
556+
557+
let test = Test(_b: 1, a: 42)
558+
print("effects-support-test: \(test)")
559+
}
560+
561+
test_effects_are_still_supported()
562+
// CHEKC: effects-support-test: Test(_a: 42, b: 0)

0 commit comments

Comments
 (0)