mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Addresses SR-2605.
If you're refactoring a `guard` into an `if`, it's easy to
accidentally end up with invalid code like this in the transition:
```
if condition else {
}
```
The parser rightly complains about the `else`, but has poor recovery
afterward, interpreting the following brace as a closure, which may in
turn lead to other unhelpful errors after:
```
error: expected '{' after 'if' condition
if condition else {
^
error: braced block of statements is an unused closure
if condition else {
^
```
Improve the diagnostics to instead explicitly detect this pattern and
mark it as an error.
6 lines
255 B
Swift
6 lines
255 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
if true else { // expected-error {{unexpected 'else' immediately following 'if' condition}}
|
|
} // expected-note@-1 {{remove 'else' to execute the braced block of statements when the condition is true}}
|
|
|