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:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user