@@ -6021,16 +6021,44 @@ Expr *ExprRewriter::coerceCallArguments(
6021
6021
};
6022
6022
6023
6023
if (paramInfo.hasExternalPropertyWrapper (paramIdx)) {
6024
- auto *param = getParameterAt (callee.getDecl (), paramIdx);
6024
+ auto *paramDecl = getParameterAt (callee.getDecl (), paramIdx);
6025
6025
auto appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];
6026
6026
auto wrapperType = solution.simplifyType (appliedWrapper.wrapperType );
6027
6027
auto initKind = appliedWrapper.initKind ;
6028
6028
6029
- using ValueKind = AppliedPropertyWrapperExpr::ValueKind;
6030
- ValueKind valueKind = (initKind == PropertyWrapperInitKind::ProjectedValue ?
6031
- ValueKind::ProjectedValue : ValueKind::WrappedValue);
6029
+ AppliedPropertyWrapperExpr::ValueKind valueKind;
6030
+ PropertyWrapperValuePlaceholderExpr *generatorArg;
6031
+ auto initInfo = paramDecl->getPropertyWrapperInitializerInfo ();
6032
+ if (initKind == PropertyWrapperInitKind::ProjectedValue) {
6033
+ valueKind = AppliedPropertyWrapperExpr::ValueKind::ProjectedValue;
6034
+ generatorArg = initInfo.getProjectedValuePlaceholder ();
6035
+ } else {
6036
+ valueKind = AppliedPropertyWrapperExpr::ValueKind::WrappedValue;
6037
+ generatorArg = initInfo.getWrappedValuePlaceholder ();
6038
+ }
6039
+
6040
+ // Coerce the property wrapper argument type to the input type of
6041
+ // the property wrapper generator function. The wrapper generator
6042
+ // has the same generic signature as the enclosing function, so we
6043
+ // can use substitutions from the callee.
6044
+ Type generatorInputType =
6045
+ generatorArg->getType ().subst (callee.getSubstitutions ());
6046
+ auto argLoc = getArgLocator (argIdx, paramIdx, param.getParameterFlags ());
6047
+
6048
+ if (generatorArg->isAutoClosure ()) {
6049
+ auto *closureType = generatorInputType->castTo <FunctionType>();
6050
+ arg = coerceToType (
6051
+ arg, closureType->getResult (),
6052
+ argLoc.withPathElement (ConstraintLocator::AutoclosureResult));
6053
+ arg = cs.buildAutoClosureExpr (arg, closureType, dc);
6054
+ }
6055
+
6056
+ arg = coerceToType (arg, generatorInputType, argLoc);
6032
6057
6033
- arg = AppliedPropertyWrapperExpr::create (ctx, callee, param, arg->getStartLoc (),
6058
+ // Wrap the argument in an applied property wrapper expr, which will
6059
+ // later turn into a call to the property wrapper generator function.
6060
+ arg = AppliedPropertyWrapperExpr::create (ctx, callee, paramDecl,
6061
+ arg->getStartLoc (),
6034
6062
wrapperType, arg, valueKind);
6035
6063
cs.cacheExprTypes (arg);
6036
6064
}
0 commit comments