@@ -5580,6 +5580,12 @@ bool MissingArgumentsFailure::isMisplacedMissingArgument(
55805580 auto argType = solution.simplifyType (solution.getType (unaryArg));
55815581 auto paramType = fnType->getParams ()[1 ].getPlainType ();
55825582
5583+ if (isExpr<ClosureExpr>(unaryArg) && argType->is <UnresolvedType>()) {
5584+ auto unwrappedParamTy = paramType->lookThroughAllOptionalTypes ();
5585+ if (unwrappedParamTy->is <FunctionType>() || unwrappedParamTy->isAny ())
5586+ return true ;
5587+ }
5588+
55835589 return TypeChecker::isConvertibleTo (argType, paramType, solution.getDC ());
55845590}
55855591
@@ -7292,7 +7298,7 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
72927298 if (diagnoseAttemptedRegexBuilder ())
72937299 return true ;
72947300
7295- if (diagnoseTrailingClosureMismatch ())
7301+ if (diagnoseClosureMismatch ())
72967302 return true ;
72977303
72987304 if (diagnoseKeyPathAsFunctionResultMismatch ())
@@ -7346,10 +7352,15 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
73467352bool ArgumentMismatchFailure::diagnoseAsNote () {
73477353 auto *locator = getLocator ();
73487354 if (auto *callee = getCallee ()) {
7349- emitDiagnosticAt (callee, diag::candidate_has_invalid_argument_at_position,
7350- getToType (), getParamPosition (),
7351- locator->isLastElement <LocatorPathElt::LValueConversion>(),
7352- getFromType ());
7355+ if (isExpr<ClosureExpr>(getAnchor ())) {
7356+ emitDiagnosticAt (callee, diag::candidate_has_invalid_closure_at_position,
7357+ getToType ());
7358+ } else {
7359+ emitDiagnosticAt (callee, diag::candidate_has_invalid_argument_at_position,
7360+ getToType (), getParamPosition (),
7361+ locator->isLastElement <LocatorPathElt::LValueConversion>(),
7362+ getFromType ());
7363+ }
73537364 return true ;
73547365 }
73557366
@@ -7633,15 +7644,16 @@ bool ArgumentMismatchFailure::diagnoseAttemptedRegexBuilder() const {
76337644 return true ;
76347645}
76357646
7636- bool ArgumentMismatchFailure::diagnoseTrailingClosureMismatch () const {
7637- if (!Info. isTrailingClosure ( ))
7647+ bool ArgumentMismatchFailure::diagnoseClosureMismatch () const {
7648+ if (!isExpr<ClosureExpr>( getAnchor () ))
76387649 return false ;
76397650
76407651 auto paramType = getToType ();
76417652 if (paramType->lookThroughAllOptionalTypes ()->is <AnyFunctionType>())
76427653 return false ;
76437654
7644- emitDiagnostic (diag::trailing_closure_bad_param, paramType)
7655+ emitDiagnostic (diag::closure_bad_param, paramType,
7656+ Info.isTrailingClosure ())
76457657 .highlight (getSourceRange ());
76467658
76477659 if (auto overload = getCalleeOverloadChoiceIfAvailable (getLocator ())) {
0 commit comments