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

Formatting unquotes interpolation #197

Closed
mmarx opened this issue Apr 22, 2024 · 4 comments · Fixed by #210
Closed

Formatting unquotes interpolation #197

mmarx opened this issue Apr 22, 2024 · 4 comments · Fixed by #210
Assignees
Labels
bug Something isn't working correctness Output parses differently after formatting

Comments

@mmarx
Copy link

mmarx commented Apr 22, 2024

Consider foo.nix:

''
  O=''\'''${A}'
''

Formatting changes the semantics of this, turning it into an interpolation:

''
  O='''${A}'
''
foo.nix: Parses differently after formatting. This is a bug in nixfmt. Please report it at https://github.com/NixOS/nixfmt

Before formatting:
Term (IndentedString (Ann [] [[TextPart "O='''${A}'"],[]] Nothing))

After formatting:
Term (IndentedString (Ann [] [[TextPart "O='''",Interpolation Term (Token (Ann [] (Identifier "A") Nothing)),TextPart "'"],[]] Nothing))
@piegamesde piegamesde self-assigned this Apr 22, 2024
@piegamesde piegamesde added bug Something isn't working correctness Output parses differently after formatting labels Apr 22, 2024
@piegamesde
Copy link
Member

This language is cursed beyond repair, and I see no hope in fixing this without a proper formal specification of its string syntax and semantics.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-06-25/47661/1

@infinisil
Copy link
Member

Bumping this higher, since it's a correctness bug and is kind of blocking for NixOS/nixpkgs#322537. @dasJ looked into it in todays meeting, I'll copy the notes here too:

@dasJ
Copy link
Member

dasJ commented Jun 26, 2024

More details from the debugging session: It's probably the parser. The example string can be minimized to ''\'''${A}. Nixfmt parses this as:

Term
    ( IndentedString
        ( Ann []
            [
                [ TextPart "'''${A}" ]
            , []
            ] Nothing
        )
    )

while nix parses it as

"'\${A}\n"

It probably dies because the first 4 characters (''\') get converted to ' and the rest gets converted to \${A} (at least this is what nix does) while nixfmt converts the second part to ''${A}. Nixfmt doesn't escape the first single quote, resulting in 3 single quotes which does not escape the ${.

dasJ added a commit that referenced this issue Jun 26, 2024
Closes #197
@dasJ dasJ mentioned this issue Jun 26, 2024
dasJ added a commit that referenced this issue Jun 26, 2024
Closes #197
dasJ added a commit that referenced this issue Jun 26, 2024
Closes #197
dasJ added a commit that referenced this issue Jun 26, 2024
Closes #197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness Output parses differently after formatting
Projects
Status: Done
5 participants