Improve diagnostics for 'let…else' without 'guard' #81728
Labels
8000
compiler
The Swift compiler itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
feature
A feature request or implementation
parser
Area → compiler: The legacy C++ parser
swift 6.2
Motivation
The following code produces a generic "consecutive statements on a line must be separated by ';'" error:
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
thanguard 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
orvar
decl is followed byelse
, ideally recover as if the user had writtenguard let
instead. If that's not possible, at least add a dedicated diagnostic for theelse
rather than just "consecutive statements…" followed by "expected expression".Alternatives considered
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: