Skip to content

Commit e30612e

Browse files
committed
[Diagnostics] Diagnose missing argument(s) in argument positions
Diagnose situation when parameter type expects N arguments but argument has `M` where `M` < `N`, e.g.: ```swift func foo(_: (Int) -> Void) {} func bar() -> Void {} foo(bar) // expected 1 argument, got 0 ```
1 parent 65c03d5 commit e30612e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,25 @@ bool MissingArgumentsFailure::diagnoseAsError() {
35813581
if (auto *closure = dyn_cast<ClosureExpr>(anchor))
35823582
return diagnoseClosure(closure);
35833583

3584+
// This is a situation where function type is passed as an argument
3585+
// to a function type parameter and their argument arity is different.
3586+
//
3587+
// ```
3588+
// func foo(_: (Int) -> Void) {}
3589+
// func bar() {}
3590+
//
3591+
// foo(bar) // `() -> Void` vs. `(Int) -> Void`
3592+
// ```
3593+
if (locator->isLastElement(ConstraintLocator::ApplyArgToParam)) {
3594+
auto info = *getFunctionArgApplyInfo(locator);
3595+
3596+
auto *argExpr = info.getArgExpr();
3597+
emitDiagnostic(argExpr->getLoc(), diag::cannot_convert_argument_value,
3598+
info.getArgType(), info.getParamType());
3599+
// TODO: It would be great so somehow point out which arguments are missing.
3600+
return true;
3601+
}
3602+
35843603
return false;
35853604
}
35863605

0 commit comments

Comments
 (0)