Commit Graph

1 Commits

Author SHA1 Message Date
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