1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-27 20:51:00 +01:00

tests: add tests for dynamic attribute in let and inherit

Regression tests for the previous commit.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
Co-authored-by: piegames <git@piegames.de>
This commit is contained in:
Taeer Bar-Yam 2025-11-25 17:46:35 +01:00 committed by Sergei Zimmerman
parent 97abcda9cc
commit 0c0a41a81a
No known key found for this signature in database
13 changed files with 68 additions and 0 deletions

View file

@ -79,6 +79,8 @@
# Not supported by nixfmt # Not supported by nixfmt
''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$'' ''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$''
''^tests/functional/lang/eval-okay-attrs5\.nix$'' ''^tests/functional/lang/eval-okay-attrs5\.nix$''
''^tests/functional/lang/eval-fail-dynamic-attrs-inherit\.nix$''
''^tests/functional/lang/eval-fail-dynamic-attrs-inherit-2\.nix$''
# More syntax tests # More syntax tests
# These tests, or parts of them, should have been parse-* test cases. # These tests, or parts of them, should have been parse-* test cases.

View file

@ -0,0 +1,6 @@
error: dynamic attributes not allowed in inherit
at /pwd/lang/eval-fail-dynamic-attrs-inherit-2.nix:5:15:
4| {
5| inherit (a) ${"b" + ""};
| ^
6| }

View file

@ -0,0 +1,6 @@
let
a.b = 1;
in
{
inherit (a) ${"b" + ""};
}

View file

@ -0,0 +1,6 @@
error: dynamic attributes not allowed in inherit
at /pwd/lang/eval-fail-dynamic-attrs-inherit.nix:5:11:
4| {
5| inherit ${"a" + ""};
| ^
6| }

View file

@ -0,0 +1,6 @@
let
a = 1;
in
{
inherit ${"a" + ""};
}

View file

@ -0,0 +1,5 @@
error: dynamic attributes not allowed in let
at /pwd/lang/eval-fail-dynamic-attrs-let-2.nix:1:1:
1| let
| ^
2| ${"${"a"}"} = 1;

View file

@ -0,0 +1,4 @@
let
${"${"a"}"} = 1;
in
a

View file

@ -0,0 +1,5 @@
error: dynamic attributes not allowed in let
at /pwd/lang/eval-fail-dynamic-attrs-let-3.nix:1:1:
1| let
| ^
2| "${"a"}" = 1;

View file

@ -0,0 +1,4 @@
let
"${"a"}" = 1;
in
a

View file

@ -0,0 +1,5 @@
error: dynamic attributes not allowed in let
at /pwd/lang/eval-fail-dynamic-attrs-let.nix:1:1:
1| let
| ^
2| ${"a" + ""} = 1;

View file

@ -0,0 +1,4 @@
let
${"a" + ""} = 1;
in
a

View file

@ -0,0 +1 @@
{ a = 1; attrs = { b = 1; c = 1; d = 1; }; b = 1; c = 1; d = 1; }

View file

@ -0,0 +1,14 @@
# dynamic attrs are not generally allowed in `let`, and inherit, but they are if they only contain a string
let
${"a"} = 1;
attrs = rec {
b = c;
${"c"} = d;
d = a;
};
in
{
inherit ${"a"};
inherit attrs;
inherit (attrs) ${"b"} ${"c"} d;
}