[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:
Doug Gregor
2020-07-17 15:46:03 -07:00
parent 6c359cc6c0
commit 2395225df7
11 changed files with 158 additions and 94 deletions

View File

@@ -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) {