Skip to content

Commit 06216fc

Browse files
committed
[Sema] InitAccessors: Synthesize memberwise inits only with init accessor properties
1 parent e84cd81 commit 06216fc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ HasMemberwiseInitRequest::evaluate(Evaluator &evaluator,
13111311

13121312
// Record all of the properties initialized by calling init accessor.
13131313
auto properties = initAccessor->getInitializedProperties();
1314+
initializedProperties.insert(var);
13141315
initializedProperties.insert(properties.begin(), properties.end());
13151316
continue;
13161317
}

test/Interpreter/init_accessors.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,29 @@ func test_effects_are_still_supported() {
560560

561561
test_effects_are_still_supported()
562562
// CHEKC: effects-support-test: Test(_a: 42, b: 0)
563+
564+
func test_memberwise_without_stored_properties() {
565+
struct Test {
566+
var a: Int {
567+
init {
568+
print("no-stored: a = \(newValue)")
569+
}
570+
571+
get { 0 }
572+
}
573+
574+
var b: Int {
575+
init {
576+
print("no-stored: b = \(newValue)")
577+
}
578+
579+
get { 1 }
580+
}
581+
}
582+
583+
_ = Test(a: 1, b: 2)
584+
}
585+
586+
test_memberwise_without_stored_properties()
587+
// CHECK: no-stored: a = 1
588+
// CHECK-NEXT: no-stored: b = 2

0 commit comments

Comments
 (0)