Skip to content

Commit facb99d

Browse files
committed
[CSApply] Coerce wrapped arguments to the wrapper generator input type in
coerceCallArguments.
1 parent 598eef3 commit facb99d

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
@@ -6017,16 +6017,44 @@ Expr *ExprRewriter::coerceCallArguments(
60176017
};
60186018

60196019
if (paramInfo.hasExternalPropertyWrapper(paramIdx)) {
6020-
auto *param = getParameterAt(callee.getDecl(), paramIdx);
6020+
auto *paramDecl = getParameterAt(callee.getDecl(), paramIdx);
60216021
auto appliedWrapper = appliedPropertyWrappers[appliedWrapperIndex++];
60226022
auto wrapperType = solution.simplifyType(appliedWrapper.wrapperType);
60236023
auto initKind = appliedWrapper.initKind;
60246024

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

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(),
60306058
wrapperType, arg, valueKind);
60316059
cs.cacheExprTypes(arg);
60326060
}

0 commit comments

Comments
 (0)