Navigation Menu

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-11148] Separate do and while blocks generate error from legacy diagnostic #53544

Closed
robinkunde opened this issue Jul 16, 2019 · 6 comments
Closed
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

@robinkunde
Copy link
Contributor

Previous ID SR-11148
Radar None
Original Reporter @robinkunde
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, Parser, StarterBug
Assignee mkita (JIRA)
Priority Medium

md5: d1d46fcf6bad8750ff6f9a64bdc59a1b

Issue Description:

A standalone do block without the optional catch block, followed by a while block will generate the error "'do-while' statement is not allowed; use 'repeat-while' instead". This is caused by a diagnostic for dealing with legacy code using "do-while". The error disappears if the statements are separated with a semicolon.

The diagnostic could be improved by suggesting the semicolon or taking the separating newlines into account. cc @belkadan

do {

}

while true {
    break
}
@belkadan
Copy link
Contributor

@rintaro, think this is simple enough for a starter bug?

@swift-ci
Copy link
Collaborator

Comment by Michal Cichecki (JIRA)

@belkadan how do you think this should be handled? Is semicolon in the end of the do block sufficient in this case?

@belkadan
Copy link
Contributor

The semicolon would be sufficient, but it's not really standard Swift, and it would stand out in a function with no other semicolons. I'd go for suggesting the extra newline myself; Rintaro may also have suggestions.

@swift-ci
Copy link
Collaborator

Comment by Michal Cichecki (JIRA)

I agree. How would an extra newline help in this case?

@belkadan
Copy link
Contributor

Swift doesn't have do-while loops at all anymore, so we're just trying to decide when to emit the diagnostic. If the compiler can guess that the developer probably didn't write a do-while loop by accident (and was instead using a do block followed by a normal while loop), then it can just not emit the diagnostic.

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 4, 2020

Comment by Maksim Kita (JIRA)

https://github.com/apple/swift/pull/28951 merged

@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

3 participants