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 breaks compilation by wrongly reformatting nested multi-line string blocks #864

Open
ktoso opened this issue Oct 25, 2024 · 1 comment

Comments

@ktoso
Copy link

ktoso commented Oct 25, 2024

swift-format breaks compilation when reformatting code with """ includes other """ multiline strings, like these:

    let initSyntax: DeclSyntax = """
      public init(_ enumValue: \(raw: name), environment: JNIEnvironment? = nil) {
        let _environment = if let environment {
          environment
        } else {
          try! JavaVirtualMachine.shared().environment()
        }
        let classObj = try! JavaClass<Self>(in: _environment)
        switch enumValue {
      \(raw: enumFields.map {
      return """
          case .\($0.getName()):
            if let \($0.getName()) = classObj.\($0.getName()) {
              self = \($0.getName())
            } else {
              fatalError("Enum value \($0.getName()) was unexpectedly nil, please re-run Java2Swift on the most updated Java class") 
            }
      """
    }.joined(separator: "\n"))
        }
      }
      """ <<<< this gets formatted wrong

results in:

/__w/swift-java/swift-java/Sources/Java2SwiftLib/JavaTranslator.swift:586:5: error: insufficient indentation of line in multi-line string literal
584 |             }
585 |       """
586 |     }.joined(separator: "\n"))
    |     |- error: insufficient indentation of line in multi-line string literal
    |     `- note: change indentation of this line to match closing delimiter
587 |         }
588 |       }
589 |       """
    |       `- note: should match space here
590 | 

Like here: https://github.com/swiftlang/swift-java/actions/runs/11511458930/job/32044929995?pr=109

Version:

  • Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
  • Target: arm64-apple-macosx15.0
@ktoso ktoso changed the title `` swift-format breaks compilation by wrongly reformatting nested multi-line string blocks Oct 25, 2024
@ahoppen
Copy link
Member

ahoppen commented Oct 25, 2024

Synced to Apple’s issue tracker as rdar://138608242

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

2 participants