Skip to content

Commit e84cd81

Browse files
committed
[AST] InitAccessors: fallback to init accessor effects if @storageRestrictions is not used
1 parent fe17491 commit e84cd81

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
@@ -9541,15 +9541,27 @@ void AccessorDecl::printUserFacingName(raw_ostream &out) const {
95419541

95429542
ArrayRef<VarDecl *> AccessorDecl::getInitializedProperties() const {
95439543
assert(isInitAccessor());
9544+
95449545
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
95459546
return SR->getInitializesProperties(const_cast<AccessorDecl *>(this));
9547+
9548+
// Fallback to old effect style declaration.
9549+
if (auto *initAttr = getAttrs().getAttribute<InitializesAttr>())
9550+
return initAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));
9551+
95469552
return {};
95479553
}
95489554

95499555
ArrayRef<VarDecl *> AccessorDecl::getAccessedProperties() const {
95509556
assert(isInitAccessor());
9557+
95519558
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
95529559
return SR->getAccessesProperties(const_cast<AccessorDecl *>(this));
9560+
9561+
// Fallback to old effect style declaration.
9562+
if (auto *accessAttr = getAttrs().getAttribute<AccessesAttr>())
9563+
return accessAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));
9564+
95539565
return {};
95549566
}
95559567

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)