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