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

swift-format bug formatting nested #if #else #endif nodes in switch statement #779

Closed
dduan opened this issue Jul 24, 2024 · 1 comment
Closed

Comments

@dduan
Copy link
Contributor

dduan commented Jul 24, 2024

Swift format can’t properly format multiple ifconfig statements in switch statements. To reproduce, paste the following as a unit test in the swift-format unit tests:

  func testNestedPoundIfInSwitchStatement() {
    let input =
      """
      switch self {
      #if os(iOS) || os(tvOS) || os(watchOS)
      case .a:
        return 40
      #if os(iOS) || os(tvOS)
      case .e:
        return 30
      #endif
      #if os(iOS)
      case .g:
        return 2
      #endif
      #endif
      default:
        return nil
      }

      """
    var configuration = Configuration.forTesting
    configuration.indentConditionalCompilationBlocks = false
    assertPrettyPrintEqual(input: input, expected: input, linelength: 45, configuration: configuration)
  }

The test fails with:

failed - Pretty-printed result was not what was expected - Actual output (+) differed from expected output (-):
 switch self {
 #if os(iOS) || os(tvOS) || os(watchOS)
 case .a:
   return 40
 #if os(iOS) || os(tvOS)
 case .e:
   return 30
-#endif
-#if os(iOS)
+#endif#if os(iOS)
 case .g:
   return 2
 #endif
 #endif
 default:
   return nil
 }
@dduan
Copy link
Contributor Author

dduan commented Jul 24, 2024

rdar://132365692

ahoppen added a commit that referenced this issue Jul 26, 2024
Fix missing break in nested IfConfig decls. Fixes #779.
ahoppen pushed a commit to ahoppen/swift-format that referenced this issue Jul 26, 2024
ahoppen pushed a commit to ahoppen/swift-format that referenced this issue Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant