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

String gaps are collapsed even when semantically meaningful #1160

Closed
amesgen opened this issue Mar 5, 2025 · 3 comments · Fixed by #1161
Closed

String gaps are collapsed even when semantically meaningful #1160

amesgen opened this issue Mar 5, 2025 · 3 comments · Fixed by #1161
Labels
bug Something isn't working

Comments

@amesgen
Copy link
Member

amesgen commented Mar 5, 2025

Describe the bug

The string literal

"\65\ \0"

is formatted to

"\650"

which are different strings for all GHC versions but 9.12.1 (on 9.12.1, they are the same, but that is a bug that is already fixed on GHC master: https://gitlab.haskell.org/ghc/ghc/-/issues/25784).

Concretely, the first string is equal to "A0" (two characters), while the second one is equal to "ʊ" (single character).

This has been broken ever since #376.

Expected behavior

The input should be formatted to a string literal representing the same string.

I see multiple options:

  1. Never fully collapse string gaps, i.e. all gaps (when in single-line layout or in a multi-line literal) are replaced with \ \.

    The input above would be a fixed point in this case.

    I think this is the simplest option.

  2. Replace string gaps (in single-line layout or in a multi-line literal) with the special escape character \&.

    I think this is potentially confusing as \& is rarely used (I had never heard of it before.)

  3. Like 1./2., but only when necessary to be semantics-preserving.

    Not sure if this is worth the (small) additional complexity.

Environment

Ormolu 0.8.0.0 or current master (4369d7c)

@amesgen amesgen added the bug Something isn't working label Mar 5, 2025
@amesgen
Copy link
Member Author

amesgen commented Mar 5, 2025

I opened #1161 implementing option 1.


cc @brandonchinn178 in case you have thoughts as you fixed https://gitlab.haskell.org/ghc/ghc/-/issues/25784

@brandonchinn178

This comment has been minimized.

@brandonchinn178
Copy link
Collaborator

brandonchinn178 commented Mar 5, 2025

Oh! I didn't know ormolu/fourmolu automatically collapsed string gaps. Yeah, that's a bit surprising for a formatter to do, IMO. I think leaving the string gaps as is makes sense

EDIT: oh I didn't read carefully. IMO we should leave string gaps alone instead of minimizing them. But option 1 is fine too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants