Skip to content

Commit e383766

Browse files
committed
[SILGen] Handle default initialization of init accessor in memberwise init
If the property isn't memberwise initializable we need to emit its initial value and call the init accessor. This currently isn't necessary since all init accessor properties are included in the memberwise initializer, but the following commit will change this.
1 parent 1d8341b commit e383766

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
428428
selfIfaceTy, selfTy, std::move(*elti));
429429
++elti;
430430
continue;
431+
} else {
432+
// If the property isn't memberwise initialized, emit the initial
433+
// value directly.
434+
// TODO: This matches the logic below, but should we be calling
435+
// the initializer generator instead to match what we do for
436+
// `emitMemberInitializationViaInitAccessor`?
437+
auto *init = field->getParentExecutableInitializer();
438+
ASSERT(init);
439+
FullExpr scope(SGF.Cleanups, field->getParentPatternBinding());
440+
auto rvalue = SGF.emitRValue(init);
441+
emitApplyOfInitAccessor(SGF, Loc, initAccessor, resultSlot,
442+
selfIfaceTy, selfTy, std::move(rvalue));
431443
}
432444
}
433445

0 commit comments

Comments
 (0)