@@ -2129,19 +2129,35 @@ TypeCheckFunctionBodyRequest::evaluate(Evaluator &evaluator,
2129
2129
// what the type of the expression is. Take the inserted return back out.
2130
2130
body->setLastElement (func->getSingleExpressionBody ());
2131
2131
}
2132
- } else if (isa<ConstructorDecl>(AFD) &&
2133
- (body->empty () ||
2134
- !isKnownEndOfConstructor (body->getLastElement ()))) {
2135
- // For constructors, we make sure that the body ends with a "return" stmt,
2136
- // which we either implicitly synthesize, or the user can write. This
2137
- // simplifies SILGen.
2138
- SmallVector<ASTNode, 8 > Elts (body->getElements ().begin (),
2139
- body->getElements ().end ());
2140
- Elts.push_back (new (ctx) ReturnStmt (body->getRBraceLoc (),
2141
- /* value*/ nullptr ,
2142
- /* implicit*/ true ));
2143
- body = BraceStmt::create (ctx, body->getLBraceLoc (), Elts,
2144
- body->getRBraceLoc (), body->isImplicit ());
2132
+ } else if (auto *ctor = dyn_cast<ConstructorDecl>(AFD)) {
2133
+ // If this is user-defined constructor that requires `_storage`
2134
+ // variable injection, do so now so now.
2135
+ if (auto *storageVar = ctor->getLocalTypeWrapperStorageVar ()) {
2136
+ SmallVector<ASTNode, 8 > Elts;
2137
+
2138
+ Elts.push_back (storageVar->getParentPatternBinding ());
2139
+ Elts.push_back (storageVar);
2140
+
2141
+ Elts.append (body->getElements ().begin (),
2142
+ body->getElements ().end ());
2143
+
2144
+ body = BraceStmt::create (ctx, body->getLBraceLoc (), Elts,
2145
+ body->getRBraceLoc (), body->isImplicit ());
2146
+ }
2147
+
2148
+ if (body->empty () ||
2149
+ !isKnownEndOfConstructor (body->getLastElement ())) {
2150
+ // For constructors, we make sure that the body ends with a "return" stmt,
2151
+ // which we either implicitly synthesize, or the user can write. This
2152
+ // simplifies SILGen.
2153
+ SmallVector<ASTNode, 8 > Elts (body->getElements ().begin (),
2154
+ body->getElements ().end ());
2155
+ Elts.push_back (new (ctx) ReturnStmt (body->getRBraceLoc (),
2156
+ /* value*/ nullptr ,
2157
+ /* implicit*/ true ));
2158
+ body = BraceStmt::create (ctx, body->getLBraceLoc (), Elts,
2159
+ body->getRBraceLoc (), body->isImplicit ());
2160
+ }
2145
2161
}
2146
2162
2147
2163
// Typechecking, in particular ApplySolution is going to replace closures
0 commit comments