Skip to content

Commit 881f521

Browse files
committed
[Diagnostics] Diagnose missing arguments in relation to contextual type
Function type has fewer arguments than expected by context: ```swift func foo() {} let _: (Int) -> Void = foo // expected 1 argument, got 0 ```
1 parent e30612e commit 881f521

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,20 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
35083508
return true;
35093509
}
35103510

3511+
// Function type has fewer arguments than expected by context:
3512+
//
3513+
// ```
3514+
// func foo() {}
3515+
// let _: (Int) -> Void = foo
3516+
// ```
3517+
if (locator->isLastElement(ConstraintLocator::ContextualType)) {
3518+
auto &cs = getConstraintSystem();
3519+
emitDiagnostic(anchor->getLoc(), diag::cannot_convert_initializer_value,
3520+
getType(anchor), resolveType(cs.getContextualType()));
3521+
// TODO: It would be great so somehow point out which arguments are missing.
3522+
return true;
3523+
}
3524+
35113525
return false;
35123526
}
35133527

0 commit comments

Comments
 (0)