let bindings cause attrset key conflicts where merging is possible #651

Open
opened 2025-01-29 10:43:22 +00:00 by srxl · 3 comments
Member

Describe the bug

In theory, these two snippets should evaluate to the same thing:

{
  key = {
    one = 1;
  };
  
  key.two = 2;
}

and

{
  key = let
    unused = "binding";
  in {
    one = 1;
  };
  
  key.two = 2;
}

However, while the first one evaluates with no problem, the second form fails with the following error:

error: attribute 'key' already defined at «string»:2:3
       at «string»:8:3:
            7|
            8|   key.two = 2;
             |   ^

Steps To Reproduce

  1. Open a repl session (nix repl)
  2. Paste (or type) both attribute sets above into the repl session
  3. The first attribute set evaluates with no issues
  4. The second attribute set produces an error after entering the key.two = 2; line

Expected behavior

Both attribute sets should evaluate to:

{
  key = {
    one = 1;
    two = 2;
  };
}

nix --version output

nix (Lix, like Nix) 2.92.0
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux, x86_64-v4-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/ruby/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/ruby/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/ruby/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/ruby/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/ipybd6h2yy2igfprg8q0czipxl8d11d4-lix-2.92.0/share
## Describe the bug In theory, these two snippets should evaluate to the same thing: ```nix { key = { one = 1; }; key.two = 2; } ``` and ```nix { key = let unused = "binding"; in { one = 1; }; key.two = 2; } ``` However, while the first one evaluates with no problem, the second form fails with the following error: ``` error: attribute 'key' already defined at «string»:2:3 at «string»:8:3: 7| 8| key.two = 2; | ^ ``` ## Steps To Reproduce 1. Open a repl session (`nix repl`) 2. Paste (or type) both attribute sets above into the repl session 3. The first attribute set evaluates with no issues 4. The second attribute set produces an error after entering the `key.two = 2;` line ## Expected behavior Both attribute sets should evaluate to: ```nix { key = { one = 1; two = 2; }; } ``` ## `nix --version` output ``` nix (Lix, like Nix) 2.92.0 System type: x86_64-linux Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux, x86_64-v4-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /home/ruby/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/ruby/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/ruby/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/ruby/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/ipybd6h2yy2igfprg8q0czipxl8d11d4-lix-2.92.0/share ```
Owner

we understand why you expect this, but merging is syntactic sugar and your example cannot be syntactically rearranged into a merged definition. this is not a bug, it's behaving as intended (even though the the intended behavior is stupid)

we understand why you expect this, but merging is syntactic sugar and your example cannot be syntactically rearranged into a merged definition. this is not a bug, it's behaving as intended (even though the the intended behavior is stupid)
Author
Member

Yeah, makes sense - totally understand closing this one as a wontfix, just figured I'd raise it as a point to maybe at least document somewhere, since it is a little unexpected.

Yeah, makes sense - totally understand closing this one as a wontfix, just figured I'd raise it as a point to maybe at least document somewhere, since it is a little unexpected.
Owner

oh we're not closing it! this is definitely something that needs to be worked on in some way, through documentation first and overhauling the merging semantics in the future :) though we should probably also add the docs labels to make this easier to find, huh

oh we're not closing it! this is definitely something that needs to be worked on in some way, through documentation first and overhauling the merging semantics in the future :) though we should probably also add the docs labels to make this easier to find, huh
Sign in to join this conversation.
No milestone
No project
No assignees
2 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#651
No description provided.