[Sema] InitAccessors: Synthesize memberwise inits only with init accessor properties

This commit is contained in:
Pavel Yaskevich
2023-07-07 13:56:02 -07:00
parent e84cd810d1
commit 06216fc0f1
2 changed files with 27 additions and 0 deletions

View File

@@ -1311,6 +1311,7 @@ HasMemberwiseInitRequest::evaluate(Evaluator &evaluator,
// Record all of the properties initialized by calling init accessor. // Record all of the properties initialized by calling init accessor.
auto properties = initAccessor->getInitializedProperties(); auto properties = initAccessor->getInitializedProperties();
initializedProperties.insert(var);
initializedProperties.insert(properties.begin(), properties.end()); initializedProperties.insert(properties.begin(), properties.end());
continue; continue;
} }

View File

@@ -560,3 +560,29 @@ func test_effects_are_still_supported() {
test_effects_are_still_supported() test_effects_are_still_supported()
// CHEKC: effects-support-test: Test(_a: 42, b: 0) // CHEKC: effects-support-test: Test(_a: 42, b: 0)
func test_memberwise_without_stored_properties() {
struct Test {
var a: Int {
init {
print("no-stored: a = \(newValue)")
}
get { 0 }
}
var b: Int {
init {
print("no-stored: b = \(newValue)")
}
get { 1 }
}
}
_ = Test(a: 1, b: 2)
}
test_memberwise_without_stored_properties()
// CHECK: no-stored: a = 1
// CHECK-NEXT: no-stored: b = 2