mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Type checker] Improve diagnostics for trailing closures.
The change to the forward-scanning rule regressed some diagnostics, because we no longer generated the special "trailing closure mismatch" diagnostic. Reinstate the special-case "trailing closure mismatch" diagnostic, but this time do so as part of the normal argument mismatch diagnostics so it is based on type information. While here, clean up the handling of missing-argument diagnostics to deal with (multiple) trailing closures properly, so that we can (e.g) suggest adding a new labeled trailing closure at the end, rather than producing nonsensical Fix-Its. And, note that SR-12291 is broken (again) by the forward-scan matching rules.
This commit is contained in:
@@ -421,7 +421,8 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
|
||||
|
||||
// If the parameter we are looking at does not support the (unlabeled)
|
||||
// trailing closure argument, this parameter is unfulfilled.
|
||||
if (!paramInfo.acceptsUnlabeledTrailingClosureArgument(paramIdx)) {
|
||||
if (!paramInfo.acceptsUnlabeledTrailingClosureArgument(paramIdx) &&
|
||||
!ignoreNameMismatch) {
|
||||
haveUnfulfilledParams = true;
|
||||
return;
|
||||
}
|
||||
@@ -739,7 +740,10 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
|
||||
// one argument requires label and another one doesn't, but caller
|
||||
// doesn't provide either, problem is going to be identified as
|
||||
// out-of-order argument instead of label mismatch.
|
||||
const auto expectedLabel = params[paramIdx].getLabel();
|
||||
const auto expectedLabel =
|
||||
fromArgIdx == unlabeledTrailingClosureArgIndex
|
||||
? Identifier()
|
||||
: params[paramIdx].getLabel();
|
||||
const auto argumentLabel = args[fromArgIdx].getLabel();
|
||||
|
||||
if (argumentLabel != expectedLabel) {
|
||||
|
||||
Reference in New Issue
Block a user