-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser
Description
| Previous ID | SR-2605 |
| Radar | None |
| Original Reporter | @jckarter |
| Type | Bug |
| Status | Closed |
| Resolution | Done |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, DiagnosticsQoI, Parser, StarterBug |
| Assignee | @modocache |
| Priority | Medium |
md5: 4700a3a0330dc628a2226b9d21b6eb4b
Issue Description:
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:
/Users/jgroff/src/s/swift/stdlib/public/core/Optional.swift:517:32: error: expected '{' after 'if' condition
if source === _nilSentinel else {
^
/Users/jgroff/src/s/swift/stdlib/public/core/Optional.swift:517:37: error: braced block of statements is an unused closure
if source === _nilSentinel else {
^It might be friendlier to recognize this pattern and instead recover as if the else wasn't there, or as if there were an empty block before it.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser