mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] TypeWrappers: convert variable init expr into initializer default
All of the stored properties are wrapped which means that their initializers are subsummed and moved to the synthesized `init` as default arguments.
This commit is contained in:
@@ -188,6 +188,28 @@ static void maybeAddMemberwiseDefaultArg(ParamDecl *arg, VarDecl *var,
|
||||
arg->setDefaultArgumentKind(DefaultArgumentKind::StoredProperty);
|
||||
}
|
||||
|
||||
static void maybeAddTypeWrapperDefaultArg(ParamDecl *arg, VarDecl *var,
|
||||
ASTContext &ctx) {
|
||||
assert(var->isAccessedViaTypeWrapper());
|
||||
|
||||
if (!var->getParentPattern()->getSingleVar())
|
||||
return;
|
||||
|
||||
auto *PBD = var->getParentPatternBinding();
|
||||
|
||||
auto *initExpr = PBD->getInit(/*index=*/0);
|
||||
if (!initExpr)
|
||||
return;
|
||||
|
||||
// Type wrapper variables are never initialized directly,
|
||||
// initialization expression (if any) becomes an default
|
||||
// argument of the initializer synthesized by the type wrapper.
|
||||
PBD->setInitializerSubsumed(/*index=*/0);
|
||||
|
||||
arg->setDefaultExpr(initExpr, /*isTypeChecked=*/false);
|
||||
arg->setDefaultArgumentKind(DefaultArgumentKind::Normal);
|
||||
}
|
||||
|
||||
/// Describes the kind of implicit constructor that will be
|
||||
/// generated.
|
||||
enum class ImplicitConstructorKind {
|
||||
@@ -339,6 +361,8 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
|
||||
arg->setInterfaceType(var->getValueInterfaceType());
|
||||
arg->setImplicit();
|
||||
|
||||
maybeAddTypeWrapperDefaultArg(arg, var, ctx);
|
||||
|
||||
params.push_back(arg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user