Skip to content

When using multi-line string literal, formatting results in invalid code in 509.0.0 #652

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

Closed
treastrain opened this issue Oct 17, 2023 · 2 comments · Fixed by #656
Closed

Comments

@treastrain
Copy link

I'm using swift-format 509.0.0. If I prepare the following sample code and run swift-format format, it formats it into code that cannot be built.

This problem did not occur in swift-format 508.0.0. Is it a bug in swift-format 509.0.0?

import Foundation

@available(*, deprecated, renamed: "num", message: """
This is
multi-line
string
""")
func int() -> Int { 1 }

swift-format format -i Sources/main.swift
import Foundation

@available(
  *, deprecated, renamed: "num",
  message: """This is
  multi-line
  string"""
)
func int() -> Int { 1 }

@allevato
Copy link
Member

Have you observed this in other uses of multi-line strings or is it limited to attributes like @available?

@allevato
Copy link
Member

Ah-ha, I see the problem. The string here is being represented by SimpleStringLiteralExprSyntax, which literally (😁) only appears in two places: @available annotations and #sourceLocation directives. And we don't handle that node when we format.

This was probably a recent-ish change in swift-syntax that, being so narrow, we didn't have specific test coverage for.

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

Successfully merging a pull request may close this issue.

2 participants