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-13194] swift-format removes semicolon breaking up a do from a while block #316

Closed
karwa opened this issue Jul 10, 2020 · 2 comments
Closed
Assignees
Labels
bug Something isn't working swift-format

Comments

@karwa
Copy link
Contributor

karwa commented Jul 10, 2020

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

swift-format 0.50200.1, commit 07e082b

Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)

Xcode 11.5

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @karwa
Priority Medium

md5: 72e1be667614fda4d0888f44f4730dfe

Issue Description:

Consider the following code:

do {
  // some code
}

// blank lines are irrelevant

while someCondition {
  // more code
}

The compiler will fail to accept this, because it thinks you're trying to write a 'do-while' loop, and produces a diagnostic suggesting a 'repeat-while' loop instead.

If we really do want a 'do' block which coincidentally happens to be followed by a 'while' loop, we need to separate them with a semicolon:

do {
 // some code
};
while someCondition {
 // more code
}

swift-format (0.50200.1, at its default settings) will remove this semicolon, breaking the code so it no longer compiles. It is important that this semicolon not be removed.

@allevato
Copy link
Collaborator

This was fixed by #210.

@allevato
Copy link
Collaborator

I happened to be complaining to someone about this semicolon today, and in my attempts to demonstrate the problem, I found that this problem has been significantly improved in Swift 5.3. apple/swift#28951 updated the parser so that a while keyword can follow a do block if the while is on its own line. So we should keep the swift-format PR linked above for the swift-5.2-branch and releases, and remove it for Swift 5.3 (because any time we remove a semicolon between two statements, we insert a newline anyway).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 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 Something isn't working swift-format
Projects
None yet
Development

No branches or pull requests

2 participants