manual: Update Names section to exclude indented strings and URIs#15806
manual: Update Names section to exclude indented strings and URIs#15806toonn wants to merge 1 commit into
Conversation
Indented strings and URIs are string literals but they are not allowed
as names for attrsets, `let` or `inherit`. The following snippets
illustrate that they lead to syntax errors.
==> examples/ind_str-attr.nix <==
{
''indented string'' = "error: syntax error, unexpected IND_STRING_OPEN, expecting INHERIT";
}
==> examples/ind_str-inherit.nix <==
{ inherit ({ "non-indented string" = "error: syntax error, unexpected IND_STRING_OPEN"; })
''non-indented string'';
}
==> examples/ind_str-let.nix <==
let
''indented string'' = "error: syntax error, unexpected URI, expecting IN_KW or INHERIT";
in
true
==> examples/uri-attr.nix <==
{
http://example.org/foo.tar.bz2 = "error: syntax error, unexpected URI, expecting INHERIT";
}
==> examples/uri-inherit.nix <==
{ inherit ({ "http://example.org/foo.tar.bz2" = "error: syntax error, unexpected URI"; })
http://example.org/foo.tar.bz2;
}
==> examples/uri-let.nix <==
let
http://example.org/foo.tar.bz2 = "error: syntax error, unexpected URI, expecting IN_KW or INHERIT";
in
true
MattSturgeon
left a comment
There was a problem hiding this comment.
There's also the complication of writing names as raw (unquoted) interpolation, e.g.:
${if true then "foo" else null} = "bar";IIRC, this is not mentioned by the manual.
Related, but separate issue.
|
This would be a slightly different feature - dynamic attributes. |
|
I agree dynamic attributes probably deserve a bit more documentation. Technically they are documented here, in the string interpolation section, but that's not very easily found if you start at the section on Attribute sets and want to know what names are allowed (you'd have to click through string literal > string interpolation, somehow divining that the string literal section is misleading when it says interpolation elements can occur inside quotes). I could expand on them a bit but I'm not very familiar with the feature so I'd prefer someone else tackling that in a separate PR. |
|
I've opened a similar PR to the Lix manual. |
Stating that names can be "double-quoted string literals" rather than any string literals removes potential confusion.
Motivation
Reading the Nix 2.28.7 reference manual suggests attribute names are allowed to be string literals, which includes indented string literals and URIs, but this doesn't seem to be the case.
I did my tests with
nix (Nix) 2.31.4. Creating files as in the snippets below and then runningnix-instantiate --eval <snippet-file>.Context
Indented strings and URIs are string literals but they are not allowed as names for attrsets,
letorinherit. The following snippets illustrate that they lead to syntax errors.Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.