[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

@@ -595,6 +595,15 @@ public:
return StringRef(scratch.data(), scratch.size());
}
/// Whether the argument is a trailing closure.
bool isTrailingClosure() const {
if (auto trailingClosureArg =
ArgListExpr->getUnlabeledTrailingClosureIndexOfPackedArgument())
return ArgIdx >= *trailingClosureArg;
return false;
}
/// \returns The interface type for the function being applied. Note that this
/// may not a function type, for example it could be a generic parameter.
Type getFnInterfaceType() const { return FnInterfaceType; }