@@ -1347,6 +1347,16 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1347
1347
auto initialization = emitPatternBindingInitialization (PBD->getPattern (idx),
1348
1348
JumpDest::invalid ());
1349
1349
1350
+ auto getWrappedValueExpr = [&](VarDecl *var) -> Expr * {
1351
+ if (auto *orig = var->getOriginalWrappedProperty ()) {
1352
+ auto initInfo = orig->getPropertyWrapperInitializerInfo ();
1353
+ if (auto *placeholder = initInfo.getWrappedValuePlaceholder ()) {
1354
+ return placeholder->getOriginalWrappedValue ();
1355
+ }
1356
+ }
1357
+ return nullptr ;
1358
+ };
1359
+
1350
1360
auto emitInitializer = [&](Expr *initExpr, VarDecl *var, bool forLocalContext,
1351
1361
InitializationPtr &initialization) {
1352
1362
// If an initial value expression was specified by the decl, emit it into
@@ -1355,14 +1365,11 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1355
1365
1356
1366
if (forLocalContext) {
1357
1367
if (auto *orig = var->getOriginalWrappedProperty ()) {
1358
- auto initInfo = orig->getPropertyWrapperInitializerInfo ();
1359
- if (auto *placeholder = initInfo.getWrappedValuePlaceholder ()) {
1360
- initExpr = placeholder->getOriginalWrappedValue ();
1361
-
1368
+ if (auto *initExpr = getWrappedValueExpr (var)) {
1362
1369
auto value = emitRValue (initExpr);
1363
1370
emitApplyOfPropertyWrapperBackingInitializer (
1364
- PBD, orig, getForwardingSubstitutionMap (), std::move (value))
1365
- .forwardInto (*this , SILLocation (PBD), initialization.get ());
1371
+ PBD, orig, getForwardingSubstitutionMap (), std::move (value))
1372
+ .forwardInto (*this , SILLocation (PBD), initialization.get ());
1366
1373
return ;
1367
1374
}
1368
1375
}
@@ -1430,7 +1437,11 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1430
1437
1431
1438
auto &fieldInit = fieldInits[i];
1432
1439
if (initExpr) {
1433
- emitInitializer (initExpr, field, /* forLocalContext=*/ true , fieldInit);
1440
+ // If there is wrapped value expression, we have to emit a
1441
+ // backing property initializer call, otherwise let's use
1442
+ // default expression (which is just `.init()` call).
1443
+ emitInitializer (initExpr, field, bool (getWrappedValueExpr (field)),
1444
+ fieldInit);
1434
1445
} else {
1435
1446
fieldInit->finishUninitialized (*this );
1436
1447
}
0 commit comments