Skip to content

Commit e4e7613

Browse files
committed
[CSApply] Coerce wrapped arguments to the wrapper generator input type in
coerceCallArguments.
1 parent 793b492 commit e4e7613

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

lib/Sema/CSApply.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6021,16 +6021,44 @@ Expr *ExprRewriter::coerceCallArguments(
60216021
};
60226022

60236023
if (paramInfo.hasExternalPropertyWrapper(paramIdx)) {
6024-
auto *param = getParameterAt(callee.getDecl(), paramIdx);
6024+
auto *paramDecl = getParameterAt(callee.getDecl(), paramIdx);
60256025
auto appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];
60266026
auto wrapperType = solution.simplifyType(appliedWrapper.wrapperType);
60276027
auto initKind = appliedWrapper.initKind;
60286028

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);
60326057

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(),
60346062
wrapperType, arg, valueKind);
60356063
cs.cacheExprTypes(arg);
60366064
}

0 commit comments

Comments
 (0)