@@ -1549,12 +1549,11 @@ namespace {
1549
1549
ConstraintLocatorBuilder locator,
1550
1550
ConstraintLocatorBuilder calleeLocator);
1551
1551
1552
- // Resolve `@dynamicCallable` applications.
1553
- Expr *finishApplyDynamicCallable (ApplyExpr *apply,
1554
- SelectedOverload selected,
1555
- FuncDecl *method,
1556
- AnyFunctionType *methodType,
1557
- ConstraintLocatorBuilder applyFunctionLoc);
1552
+ // / Build the function and argument for a `@dynamicCallable` application.
1553
+ std::pair</* fn*/ Expr *, /* arg*/ Expr *>
1554
+ buildDynamicCallable (ApplyExpr *apply, SelectedOverload selected,
1555
+ FuncDecl *method, AnyFunctionType *methodType,
1556
+ ConstraintLocatorBuilder applyFunctionLoc);
1558
1557
1559
1558
private:
1560
1559
// / Simplify the given type by substituting all occurrences of
@@ -7153,12 +7152,11 @@ static Expr *buildCallAsFunctionMethodRef(
7153
7152
}
7154
7153
7155
7154
// Resolve `@dynamicCallable` applications.
7156
- Expr *
7157
- ExprRewriter::finishApplyDynamicCallable (ApplyExpr *apply,
7158
- SelectedOverload selected,
7159
- FuncDecl *method,
7160
- AnyFunctionType *methodType,
7161
- ConstraintLocatorBuilder loc) {
7155
+ std::pair<Expr *, Expr *>
7156
+ ExprRewriter::buildDynamicCallable (ApplyExpr *apply, SelectedOverload selected,
7157
+ FuncDecl *method,
7158
+ AnyFunctionType *methodType,
7159
+ ConstraintLocatorBuilder loc) {
7162
7160
auto &ctx = cs.getASTContext ();
7163
7161
auto *fn = apply->getFn ();
7164
7162
@@ -7210,8 +7208,7 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
7210
7208
handleStringLiteralExpr (cast<LiteralExpr>(labelExpr));
7211
7209
7212
7210
Expr *valueExpr = coerceToType (arg->getElement (i), valueType, loc);
7213
- if (!valueExpr)
7214
- return nullptr ;
7211
+ assert (valueExpr && " Failed to coerce?" );
7215
7212
Expr *pair = TupleExpr::createImplicit (ctx, {labelExpr, valueExpr}, {});
7216
7213
auto eltTypes = { TupleTypeElt (keyType), TupleTypeElt (valueType) };
7217
7214
cs.setType (pair, TupleType::get (eltTypes, ctx));
@@ -7224,22 +7221,21 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
7224
7221
}
7225
7222
argument->setImplicit ();
7226
7223
7227
- // Construct call to the `dynamicallyCall` method.
7228
- auto result = CallExpr::createImplicit (ctx, member, argument,
7229
- { argumentLabel });
7230
- cs.setType (result->getArg (), AnyFunctionType::composeInput (ctx, params,
7231
- false ));
7232
- cs.setType (result, methodType->getResult ());
7233
- cs.cacheExprTypes (result);
7234
- return result;
7224
+ // Build the argument list expr.
7225
+ argument = TupleExpr::createImplicit (ctx, {argument}, {argumentLabel});
7226
+ cs.setType (argument,
7227
+ TupleType::get ({TupleTypeElt (argumentType, argumentLabel)}, ctx));
7228
+
7229
+ return std::make_pair (member, argument);
7235
7230
}
7236
7231
7237
7232
Expr *ExprRewriter::finishApply (ApplyExpr *apply, Type openedType,
7238
7233
ConstraintLocatorBuilder locator,
7239
7234
ConstraintLocatorBuilder calleeLocator) {
7240
7235
auto &ctx = cs.getASTContext ();
7241
-
7242
- auto fn = apply->getFn ();
7236
+
7237
+ auto *arg = apply->getArg ();
7238
+ auto *fn = apply->getFn ();
7243
7239
7244
7240
bool hasTrailingClosure =
7245
7241
isa<CallExpr>(apply) && cast<CallExpr>(apply)->hasTrailingClosure ();
@@ -7408,7 +7404,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
7408
7404
if (method && methodType) {
7409
7405
// Handle a call to a @dynamicCallable method.
7410
7406
if (isValidDynamicCallableMethod (method, methodType))
7411
- return finishApplyDynamicCallable (
7407
+ std::tie (fn, arg) = buildDynamicCallable (
7412
7408
apply, *selected, method, methodType, applyFunctionLoc);
7413
7409
}
7414
7410
}
@@ -7465,13 +7461,11 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
7465
7461
// the function.
7466
7462
SmallVector<Identifier, 2 > argLabelsScratch;
7467
7463
if (auto fnType = cs.getType (fn)->getAs <FunctionType>()) {
7468
- auto origArg = apply->getArg ();
7469
- Expr *arg = coerceCallArguments (origArg, fnType, callee,
7470
- apply,
7471
- apply->getArgumentLabels (argLabelsScratch),
7472
- hasTrailingClosure,
7473
- locator.withPathElement (
7474
- ConstraintLocator::ApplyArgument));
7464
+ arg = coerceCallArguments (arg, fnType, callee, apply,
7465
+ apply->getArgumentLabels (argLabelsScratch),
7466
+ hasTrailingClosure,
7467
+ locator.withPathElement (
7468
+ ConstraintLocator::ApplyArgument));
7475
7469
if (!arg) {
7476
7470
return nullptr ;
7477
7471
}
0 commit comments