Skip to content

Commit 24b2bca

Browse files
committed
[Sema] TypeWrappers: Subsume property init before injecting it into $Storage
It was done in `maybeAddTypeWrapperDefaultArg` before because user-defined initializers weren't supported but now property initializers need to be subsumed earlier to make sure that SILGen doesn't try to emit them into user-defined initializers.
1 parent 73e9f27 commit 24b2bca

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,6 @@ static void maybeAddTypeWrapperDefaultArg(ParamDecl *arg, VarDecl *var,
213213
if (!initExpr)
214214
return;
215215

216-
// Type wrapper variables are never initialized directly,
217-
// initialization expression (if any) becomes an default
218-
// argument of the initializer synthesized by the type wrapper.
219-
{
220-
// Since type wrapper is applied to backing property, that's
221-
// the the initializer it subsumes.
222-
if (var->hasAttachedPropertyWrapper()) {
223-
auto *backingVar = var->getPropertyWrapperBackingProperty();
224-
PBD = backingVar->getParentPatternBinding();
225-
}
226-
227-
PBD->setInitializerSubsumed(/*index=*/0);
228-
}
229-
230216
arg->setDefaultExpr(initExpr, PBD->isInitializerChecked(/*index=*/0));
231217
arg->setDefaultArgumentKind(DefaultArgumentKind::Normal);
232218
}

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ VarDecl *GetTypeWrapperStorageForProperty::evaluate(Evaluator &evaluator,
227227
auto *storage = wrappedType->getTypeWrapperStorageDecl();
228228
assert(storage);
229229

230+
// Type wrapper variables are never initialized directly,
231+
// initialization expression (if any) becomes an default
232+
// argument of the initializer synthesized by the type wrapper.
233+
if (auto *PBD = property->getParentPatternBinding()) {
234+
PBD->setInitializerSubsumed(/*index=*/0);
235+
}
236+
230237
return injectProperty(storage, property->getName(),
231238
property->getValueInterfaceType(),
232239
property->getIntroducer(), AccessLevel::Internal);

0 commit comments

Comments
 (0)