Commit Graph

12 Commits

Author SHA1 Message Date
Doug Gregor
25d40125e9 [Trailing closures] Bias toward the backward scan for ambiguities.
This approach, suggested by Xiaodi Wu, provides better source
compatibility for existing Swift code, by breaking ties in favor of the
existing Swift semantics. Each time the backward-scan rule is needed
(and differs from the forward-scan result), we will produce a warning
+ Fix-It to prepare for Swift 6 where the backward rule can be
removed.
2020-07-24 08:47:51 -07:00
Doug Gregor
4acb094677 Fix a NULL pointer dereference and update test cases. 2020-07-24 08:11:25 -07:00
Doug Gregor
2395225df7 [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.
2020-07-24 08:10:54 -07:00
Rintaro Ishizaki
0355a87eea [Parse] Parse editor placeholder as a labeled trailng closure
So that SourceKit can expand them to closure literals.
2020-05-06 01:56:41 -04:00
John McCall
40836a0045 Resolve an ambiguity with the multiple-trailing-closure syntax in favor of parsing default: labels. 2020-05-06 01:56:41 -04:00
John McCall
938c84f5f7 Fix test. 2020-05-06 01:56:41 -04:00
John McCall
67838cd609 Call out another bad diagnostic, delete a redundant test. 2020-05-06 01:56:40 -04:00
John McCall
882035f003 Implement the conservative option for typechecking multiple trailing closures.
The current approach for type-checking single trailing closures
is to scan backwards from the end of the parameter list, looking
for something that can be passed a closure.  This generalizes that
to perform label-matching in reverse on any later trailing closures,
then pick up from that point when trying to place the unlabeled
trailing closure.

The current approach is really not a good language rule, but changing
it as much as we'd really like will require evolution approval and a
source break, so we have to be cautious.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
6bd20ca768 [Parse] Allow multiple trailing closures to be delimited by _:
Syntax like `foo { _: { ... } }` is going to be parsed as a single
trailing closure.
2020-05-06 01:56:40 -04:00
Nathan Hawes
4c4990ead4 Multiple trailing closure fixes
- Diagnose non-closure-literals after label + colon
- Form a TupleExpr, rather than a ParenExpr for a single labelled trailing closure.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
ed5b6958f3 [Parse] Introduce tailored diagnostics for an invalid trailing closures block
If block is not just a list of labeled closures produce a tailored
diagnostic and skip over invalid code.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
93c0d85a96 [Parser] NFC: Move multiple trailing closures tests into a separate file 2020-05-06 01:56:40 -04:00