Open
Description
Motivation
The following code produces a generic "consecutive statements on a line must be separated by ';'" error:
let specific = general as? Specific else {
return nil
}
However, there's a reason somewhat might write this: this is the Rust syntax for pattern-match-or-exit-scope (though in Rust it's closer to guard case
than guard let
). Even without that justification, else
is not normally the start of a statement anyway, so better recovery is possible.
Proposed solution
If a let
or var
decl is followed by else
, ideally recover as if the user had written guard let
instead. If that's not possible, at least add a dedicated diagnostic for the else
rather than just "consecutive statements…" followed by "expected expression".
Alternatives considered
No response
Additional information
No response