Disallow merging attrs of recursive attrsets #350

Open
opened 2024-05-25 01:17:37 +00:00 by qyriad · 0 comments
Owner

The behavior of recursive attrsets with the nested attr key syntax is rather confusing. In the following attrset:

{
  a = rec { b = 5; };
  a.c = b;
}

b is in scope in value-position when setting a.c, which only makes sense when you think through the desugaring and recognize that the above expression is equivalent to:

{
  a = rec { b = 5; c = b; };
}

However in more complex expressions this can get so unintuitive that it's unclear what an attrset literal should even evaluate to:

let
  d = 1;
in {
  a = rec {
    b = rec {
      c = d;
    };
    d = 2;
  };
  a.b.d = 3;
}

Recursive attrsets are only rarely notably useful over let expressions and in many other cases an antipattern. Simply disallowing merging for rec attrsets is the least surprising thing we could do here.

See also: #329

The behavior of [recursive attrsets](https://docs.lix.systems/manual/nightly/language/constructs.html#recursive-sets) with the nested attr key syntax is rather confusing. In the following attrset: ```nix { a = rec { b = 5; }; a.c = b; } ``` `b` is in scope in value-position when setting `a.c`, which only makes sense when you think through the desugaring and recognize that the above expression is equivalent to: ```nix { a = rec { b = 5; c = b; }; } ``` However in more complex expressions this can get so unintuitive that it's unclear what an attrset literal should even evaluate to: ```nix let d = 1; in { a = rec { b = rec { c = d; }; d = 2; }; a.b.d = 3; } ``` --- Recursive attrsets are only rarely notably useful over let expressions and in many other cases an antipattern. Simply disallowing merging for rec attrsets is the least surprising thing we could do here. See also: #329
qyriad added this to the post-release milestone 2024-05-25 01:17:37 +00:00
qyriad added the
Needs Langver
label 2024-05-25 01:17:37 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#350
No description provided.