@@ -220,6 +220,21 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
220
220
221
221
// Cleanup after this initialization.
222
222
FullExpr scope (SGF.Cleanups , field->getParentPatternBinding ());
223
+
224
+ // If this is a property wrapper backing storage var that isn't
225
+ // memberwise initialized and has an original wrapped value, apply
226
+ // the property wrapper backing initializer.
227
+ if (auto *wrappedVar = field->getOriginalWrappedProperty ()) {
228
+ auto wrappedInfo = wrappedVar->getPropertyWrapperBackingPropertyInfo ();
229
+ if (wrappedInfo.originalInitialValue ) {
230
+ auto arg = SGF.emitRValue (wrappedInfo.originalInitialValue );
231
+ maybeEmitPropertyWrapperInitFromValue (SGF, Loc, field, subs,
232
+ std::move (arg))
233
+ .forwardInto (SGF, Loc, init.get ());
234
+ continue ;
235
+ }
236
+ }
237
+
223
238
SGF.emitExprInto (field->getParentInitializer (), init.get ());
224
239
}
225
240
}
@@ -235,27 +250,38 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
235
250
for (VarDecl *field : decl->getStoredProperties ()) {
236
251
auto fieldTy =
237
252
selfTy.getFieldType (field, SGF.SGM .M , SGF.getTypeExpansionContext ());
238
- SILValue v ;
253
+ RValue value ;
239
254
240
255
// If it's memberwise initialized, do so now.
241
256
if (field->isMemberwiseInitialized (/* preferDeclaredProperties=*/ false )) {
242
257
FullExpr scope (SGF.Cleanups , field->getParentPatternBinding ());
243
258
assert (elti != eltEnd && " number of args does not match number of fields" );
244
259
(void )eltEnd;
245
- v = maybeEmitPropertyWrapperInitFromValue (
246
- SGF, Loc, field, subs, std::move (*elti))
247
- .forwardAsSingleStorageValue (SGF, fieldTy, Loc);
260
+ value = std::move (*elti);
248
261
++elti;
249
262
} else {
250
263
// Otherwise, use its initializer.
251
264
assert (field->isParentInitialized ());
265
+ Expr *init = field->getParentInitializer ();
266
+
267
+ // If this is a property wrapper backing storage var that isn't
268
+ // memberwise initialized, use the original wrapped value if it exists.
269
+ if (auto *wrappedVar = field->getOriginalWrappedProperty ()) {
270
+ auto wrappedInfo = wrappedVar->getPropertyWrapperBackingPropertyInfo ();
271
+ if (wrappedInfo.originalInitialValue ) {
272
+ init = wrappedInfo.originalInitialValue ;
273
+ }
274
+ }
252
275
253
- // Cleanup after this initialization.
254
- FullExpr scope (SGF.Cleanups , field->getParentPatternBinding ());
255
- v = SGF.emitRValue (field->getParentInitializer ())
256
- .forwardAsSingleStorageValue (SGF, fieldTy, Loc);
276
+ value = SGF.emitRValue (init);
257
277
}
258
278
279
+ // Cleanup after this initialization.
280
+ FullExpr scope (SGF.Cleanups , field->getParentPatternBinding ());
281
+ SILValue v = maybeEmitPropertyWrapperInitFromValue (SGF, Loc, field, subs,
282
+ std::move (value))
283
+ .forwardAsSingleStorageValue (SGF, fieldTy, Loc);
284
+
259
285
eltValues.push_back (v);
260
286
}
261
287
0 commit comments