Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2605] Cascading failures trying to parse if <expr> else #45210

Closed
jckarter opened this issue Sep 9, 2016 · 6 comments
Closed

[SR-2605] Cascading failures trying to parse if <expr> else #45210

jckarter opened this issue Sep 9, 2016 · 6 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers parser Area → compiler: The legacy C++ parser

Comments

@jckarter
Copy link
Member

jckarter commented Sep 9, 2016

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.

@modocache
Copy link
Mannequin

modocache mannequin commented Dec 15, 2016

I'm a bit stuck working on https://bugs.swift.org/browse/SR-2442, but I think I can accomplish this. Will send a pull request as a rough first pass shortly.

@modocache
Copy link
Mannequin

modocache mannequin commented Dec 15, 2016

#6298 - Detecting the pattern is straightforward. Still looking into how to prevent the cascading failures.

@modocache
Copy link
Mannequin

modocache mannequin commented Dec 15, 2016

OK, updated #6298 I think it should now do pretty much what you intended, Joe. Let me know if you have feedback on the diagnostic message.

@modocache
Copy link
Mannequin

modocache mannequin commented Dec 20, 2016

I merged #6298 which I think resolves this issue. Joe, please confirm and close 🙂

@jckarter
Copy link
Member Author

Looks great, thanks Brian!

@modocache
Copy link
Mannequin

modocache mannequin commented Dec 21, 2016

You're quite welcome![]( Thanks for a fantastic starter bug)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

1 participant