Skip to content

Commit fe2dec5

Browse files
committed
[SE-0400] All properties with init accessors become part of the memberwise init
Per the clarification during the review thread, all properties with init accessors (including those that do not initialize any underlying storage) are part of the memberwise initializer.
1 parent bd11fce commit fe2dec5

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7180,7 +7180,7 @@ bool VarDecl::isMemberwiseInitialized(bool preferDeclaredProperties) const {
71807180
// other stored properties.
71817181
if (hasInitAccessor()) {
71827182
if (auto *init = getAccessor(AccessorKind::Init))
7183-
return init->getAttrs().hasAttribute<InitializesAttr>();
7183+
return true;
71847184
}
71857185

71867186
// If this is a computed property, it's not memberwise initialized unless

lib/SILGen/SILGenConstructor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
360360
decl->collectPropertiesInitializableByInitAccessors(initializedViaAccessor);
361361

362362
// Emit the indirect return argument, if any.
363+
bool hasInitAccessors = !decl->getInitAccessorProperties().empty();
363364
SILValue resultSlot;
364365
if (selfTy.isAddress()) {
365366
auto &AC = SGF.getASTContext();
@@ -371,7 +372,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
371372
VD->setSpecifier(ParamSpecifier::InOut);
372373
VD->setInterfaceType(selfIfaceTy);
373374
resultSlot = SGF.F.begin()->createFunctionArgument(selfTy, VD);
374-
} else if (!initializedViaAccessor.empty()) {
375+
} else if (hasInitAccessors) {
375376
// Allocate "self" on stack which we are going to use to
376377
// reference/init fields and then load to return.
377378
resultSlot = SGF.emitTemporaryAllocation(Loc, selfTy);
@@ -504,7 +505,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
504505
}
505506

506507
// Load as "take" from our stack allocation and return.
507-
if (!selfTy.isAddress() && !initializedViaAccessor.empty()) {
508+
if (!selfTy.isAddress() && hasInitAccessors) {
508509
auto resultValue = SGF.B.emitLoadValueOperation(
509510
Loc, resultSlot, LoadOwnershipQualifier::Take);
510511

lib/Sema/CodeSynthesis.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,10 +1300,6 @@ HasMemberwiseInitRequest::evaluate(Evaluator &evaluator,
13001300
if (!var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true))
13011301
continue;
13021302

1303-
// If init accessors are not involved, we are done.
1304-
if (initializedViaAccessor.empty())
1305-
return true;
1306-
13071303
// Check whether use of init accessors results in access to uninitialized
13081304
// properties.
13091305

test/Interpreter/init_accessors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func test_memberwise_ordering() {
385385
var _c: Int
386386
}
387387

388-
let test3 = Test3(_a: 1, _b: 2, _c: 3)
388+
let test3 = Test3(_a: 1, _b: 2, pair: (1, 2), _c: 3)
389389
print("test-memberwise-ordering-3: \(test3)")
390390
}
391391

test/decl/var/init_accessors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func test_memberwise_ordering() {
425425
var _c: Int
426426
}
427427

428-
_ = Test4(_a: 0, _b: 1, _c: 2) // Ok
428+
_ = Test4(_a: 0, _b: 1, pair: (1, 2), _c: 2) // Ok
429429

430430
struct Test5 {
431431
var _a: Int

0 commit comments

Comments
 (0)