Files
swift-mirror/test/stmt/if_unexpected_else.swift
Brian Gesiak d44dc26d1b [Parse] Improve diagnostics for if-condition-else
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.
2016-12-15 19:51:17 -05:00

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}}