@@ -6030,16 +6030,44 @@ Expr *ExprRewriter::coerceCallArguments(
60306030 };
60316031
60326032 if (paramInfo.hasExternalPropertyWrapper (paramIdx)) {
6033- auto *param = getParameterAt (callee.getDecl (), paramIdx);
6033+ auto *paramDecl = getParameterAt (callee.getDecl (), paramIdx);
60346034 auto appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];
60356035 auto wrapperType = solution.simplifyType (appliedWrapper.wrapperType );
60366036 auto initKind = appliedWrapper.initKind ;
60376037
6038- using ValueKind = AppliedPropertyWrapperExpr::ValueKind;
6039- ValueKind valueKind = (initKind == PropertyWrapperInitKind::ProjectedValue ?
6040- ValueKind::ProjectedValue : ValueKind::WrappedValue);
6038+ AppliedPropertyWrapperExpr::ValueKind valueKind;
6039+ PropertyWrapperValuePlaceholderExpr *generatorArg;
6040+ auto initInfo = paramDecl->getPropertyWrapperInitializerInfo ();
6041+ if (initKind == PropertyWrapperInitKind::ProjectedValue) {
6042+ valueKind = AppliedPropertyWrapperExpr::ValueKind::ProjectedValue;
6043+ generatorArg = initInfo.getProjectedValuePlaceholder ();
6044+ } else {
6045+ valueKind = AppliedPropertyWrapperExpr::ValueKind::WrappedValue;
6046+ generatorArg = initInfo.getWrappedValuePlaceholder ();
6047+ }
6048+
6049+ // Coerce the property wrapper argument type to the input type of
6050+ // the property wrapper generator function. The wrapper generator
6051+ // has the same generic signature as the enclosing function, so we
6052+ // can use substitutions from the callee.
6053+ Type generatorInputType =
6054+ generatorArg->getType ().subst (callee.getSubstitutions ());
6055+ auto argLoc = getArgLocator (argIdx, paramIdx, param.getParameterFlags ());
6056+
6057+ if (generatorArg->isAutoClosure ()) {
6058+ auto *closureType = generatorInputType->castTo <FunctionType>();
6059+ arg = coerceToType (
6060+ arg, closureType->getResult (),
6061+ argLoc.withPathElement (ConstraintLocator::AutoclosureResult));
6062+ arg = cs.buildAutoClosureExpr (arg, closureType, dc);
6063+ }
60416064
6042- arg = AppliedPropertyWrapperExpr::create (ctx, callee, param, arg->getStartLoc (),
6065+ arg = coerceToType (arg, generatorInputType, argLoc);
6066+
6067+ // Wrap the argument in an applied property wrapper expr, which will
6068+ // later turn into a call to the property wrapper generator function.
6069+ arg = AppliedPropertyWrapperExpr::create (ctx, callee, paramDecl,
6070+ arg->getStartLoc (),
60436071 wrapperType, arg, valueKind);
60446072 cs.cacheExprTypes (arg);
60456073 }
@@ -8416,13 +8444,18 @@ static Optional<SolutionApplicationTarget> applySolutionToInitialization(
84168444 // been subsumed by the backing property.
84178445 if (wrappedVar) {
84188446 ASTContext &ctx = cs.getASTContext ();
8419- wrappedVar->getParentPatternBinding ()->setInitializerSubsumed (0 );
84208447 ctx.setSideCachedPropertyWrapperBackingPropertyType (
84218448 wrappedVar, initType->mapTypeOutOfContext ());
84228449
84238450 // Record the semantic initializer on the outermost property wrapper.
84248451 wrappedVar->getAttachedPropertyWrappers ().front ()
84258452 ->setSemanticInit (initializer);
8453+
8454+ // If this is a wrapped parameter, we're done.
8455+ if (isa<ParamDecl>(wrappedVar))
8456+ return resultTarget;
8457+
8458+ wrappedVar->getParentPatternBinding ()->setInitializerSubsumed (0 );
84268459 }
84278460
84288461 // Coerce the pattern to the type of the initializer.
0 commit comments