Skip to content

Commit 862c9d4

Browse files
committed
[SILGen] TypeWrappers: Make sure that memberwise init of $Storage is always emitted
Although it might not be used from user-defined code directly it's still required for injected `self.$_storage = ...` performed by DI.
1 parent 224708d commit 862c9d4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,24 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
14301430
SILDeclRef constant(decl);
14311431
DeclContext *declCtx = decl->getDeclContext();
14321432

1433+
// Make sure that memberwise initializer of $Storage
1434+
// in a type wrapped type is always emitted because
1435+
// it would later be used to initialize $storage property.
1436+
if (auto *SD = declCtx->getSelfStructDecl()) {
1437+
auto &ctx = SD->getASTContext();
1438+
if (SD->getName() == ctx.Id_TypeWrapperStorage &&
1439+
decl->isMemberwiseInitializer()) {
1440+
#ifndef NDEBUG
1441+
auto *wrapped = SD->getDeclContext()->getSelfNominalTypeDecl();
1442+
assert(wrapped->hasTypeWrapper());
1443+
#endif
1444+
1445+
emitOrDelayFunction(*this, constant,
1446+
/*forceEmission=*/true);
1447+
return;
1448+
}
1449+
}
1450+
14331451
if (declCtx->getSelfClassDecl()) {
14341452
// Designated initializers for classes, as well as @objc convenience
14351453
// initializers, have have separate entry points for allocation and

0 commit comments

Comments
 (0)