You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
do {
// some code
}
// blank lines are irrelevantwhilesomeCondition {
// 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
};
whilesomeCondition {
// 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.
The text was updated successfully, but these errors were encountered:
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).
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
md5: 72e1be667614fda4d0888f44f4730dfe
Issue Description:
Consider the following 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:
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.
The text was updated successfully, but these errors were encountered: