@@ -6495,12 +6495,10 @@ static bool isValidDynamicCallableMethod(FuncDecl *method,
6495
6495
return true ;
6496
6496
}
6497
6497
6498
- // Resolve `callAsFunction` method applications .
6499
- static Expr *finishApplyCallAsFunctionMethod (
6498
+ // Build a reference to a `callAsFunction` method.
6499
+ static Expr *buildCallAsFunctionMethodRef (
6500
6500
ExprRewriter &rewriter, ApplyExpr *apply, SelectedOverload selected,
6501
- AnyFunctionType *openedMethodType,
6502
6501
ConstraintLocatorBuilder applyFunctionLoc) {
6503
- auto &cs = rewriter.cs ;
6504
6502
auto *fn = apply->getFn ();
6505
6503
auto choice = selected.choice ;
6506
6504
// Create direct reference to `callAsFunction` method.
@@ -6512,21 +6510,7 @@ static Expr *finishApplyCallAsFunctionMethod(
6512
6510
if (!declRef)
6513
6511
return nullptr ;
6514
6512
declRef->setImplicit (apply->isImplicit ());
6515
- apply->setFn (declRef);
6516
- // Coerce argument to input type of the `callAsFunction` method.
6517
- auto callee = rewriter.resolveConcreteDeclRef (choice.getDecl (),
6518
- applyFunctionLoc);
6519
- SmallVector<Identifier, 2 > argLabelsScratch;
6520
- auto *arg = rewriter.coerceCallArguments (
6521
- apply->getArg (), openedMethodType, callee, apply,
6522
- apply->getArgumentLabels (argLabelsScratch), apply->hasTrailingClosure (),
6523
- applyFunctionLoc);
6524
- if (!arg)
6525
- return nullptr ;
6526
- apply->setArg (arg);
6527
- cs.setType (apply, openedMethodType->getResult ());
6528
- cs.cacheExprTypes (apply);
6529
- return apply;
6513
+ return declRef;
6530
6514
}
6531
6515
6532
6516
// Resolve `@dynamicCallable` applications.
@@ -6768,12 +6752,19 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
6768
6752
auto methodType =
6769
6753
simplifyType (selected->openedType )->getAs <AnyFunctionType>();
6770
6754
if (method && methodType) {
6771
- if (method->isCallAsFunctionMethod ())
6772
- return finishApplyCallAsFunctionMethod (
6773
- *this , apply, *selected, methodType, applyFunctionLoc);
6774
- if (methodType && isValidDynamicCallableMethod (method, methodType))
6755
+ // Handle a call to a @dynamicCallable method.
6756
+ if (isValidDynamicCallableMethod (method, methodType))
6775
6757
return finishApplyDynamicCallable (
6776
6758
apply, *selected, method, methodType, applyFunctionLoc);
6759
+
6760
+ // If this is an implicit call to a callAsFunction method, build the
6761
+ // appropriate member reference.
6762
+ if (method->isCallAsFunctionMethod ()) {
6763
+ fn = buildCallAsFunctionMethodRef (*this , apply, *selected,
6764
+ applyFunctionLoc);
6765
+ if (!fn)
6766
+ return nullptr ;
6767
+ }
6777
6768
}
6778
6769
}
6779
6770
0 commit comments