Invalid suggestions for some "ill-defined escapes" in multiline strings #1114

Open
opened 2026-02-01 19:11:33 +00:00 by alois31 · 2 comments
Member

Describe the bug

Some of the new "ill-defined escape" warnings, in multiline strings at least, provide invalid suggestions, that will change the semantics when applied.

Steps To Reproduce

  1. Open nix repl
  2. Evaluate a multiline string whose first character is an escaped space: ''''\ ''.
  3. Observe that the result is " " (as expected), but the warning suggests to remove the ''\, which is incorrect because then the space will be considered indentation and is stripped.
  4. Evaluate a multiline string containing an unusually escaped dollar sign before a brace: ''''\${}''
  5. Observe that the result is "\${}", but the warning suggests to remove the ''\, which is incorrect because then the dollar sign will introduce an interpolation, leading to a syntax error.

Expected behavior

If there is a warning, it is actionable and the suggestion it contains is correct. More specifically:

  • The first suggestion is incorrect only at the very beginning of the string. However, there I don't know a better way to achieve the same result.
  • The second suggestion is incorrect only before a brace, in which case the slightly simpler way to escape the dollar sign would be ''$.

Given that escapes like ''$ are accepted even if they are not needed, maybe the best way forward for now is to allow escaping space with ''\, and either allow the dollar sign too or suggest ''$ instead?

nix --version output

nix (Lix, like Nix) 2.95.0
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: […]
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/iyij6yf5cfnb5cbn13yqr2vnbg6w66bp-lix-2.95.0/share

Additional context

This has been reproduced on commit 64d610fddc, it just doesn't show up in the nix --version output because I forgot to wire that up again in my system configuration.

## Describe the bug Some of the new "ill-defined escape" warnings, in multiline strings at least, provide invalid suggestions, that will change the semantics when applied. ## Steps To Reproduce 1. Open `nix repl` 2. Evaluate a multiline string whose first character is an escaped space: `''''\ ''`. 3. Observe that the result is `" "` (as expected), but the warning suggests to remove the `''\`, which is incorrect because then the space will be considered indentation and is stripped. 4. Evaluate a multiline string containing an unusually escaped dollar sign before a brace: `''''\${}''` 5. Observe that the result is `"\${}"`, but the warning suggests to remove the `''\`, which is incorrect because then the dollar sign will introduce an interpolation, leading to a syntax error. ## Expected behavior If there is a warning, it is actionable and the suggestion it contains is correct. More specifically: * The first suggestion is incorrect only at the very beginning of the string. However, there I don't know a better way to achieve the same result. * The second suggestion is incorrect only before a brace, in which case the slightly simpler way to escape the dollar sign would be `''$`. Given that escapes like `''$` are accepted even if they are not needed, maybe the best way forward for now is to allow escaping space with `''\`, and either allow the dollar sign too or suggest `''$` instead? ## `nix --version` output nix (Lix, like Nix) 2.95.0 System type: x86_64-linux Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: […] Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/iyij6yf5cfnb5cbn13yqr2vnbg6w66bp-lix-2.95.0/share ## Additional context This has been reproduced on commit 64d610fddca5235920369818dcd3e8a3fa4579d7, it just doesn't show up in the `nix --version` output because I forgot to wire that up again in my system configuration.
pennae added this to the 2.95 milestone 2026-02-01 19:34:07 +00:00
Member

This issue was mentioned on Gerrit on the following CLs:

  • comment in cl/5049 ("deprecated-features/broken-string-escape: Improve warning message")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/5049", "number": 5049, "kind": "comment"}], "cl_meta": {"5049": {"change_title": "deprecated-features/broken-string-escape: Improve warning message"}}} --> This issue was mentioned on Gerrit on the following CLs: * comment in [cl/5049](https://gerrit.lix.systems/c/lix/+/5049) ("deprecated-features/broken-string-escape: Improve warning message")
Member

5. is already being addressed by the fixup CL. About the space, after removing the escape another warning about the indentation stripping will appear. There generally is no straightforward way to have indented strings start with spaces due to their nature (Not counting hacks like ${}, or, for that matter, ''\ ), so I don't think that aspect can really be "fixed".

5\. is already being addressed by the fixup CL. About the space, after removing the escape another warning about the indentation stripping will appear. There generally is no straightforward way to have *indented* strings start with spaces due to their nature (Not counting hacks like `${}`, or, for that matter, `''\ `), so I don't think that aspect can really be "fixed".
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lix-project/lix#1114
No description provided.