nix::parser::State::addAttr: Improve error message

For some reason that eludes me, it used to only print the last attribute
instead of the full chain.

Change-Id: I2f5f6e85e2b1ab3ab20a9c99bf06d1e45a4d09bb
This commit is contained in:
piegames
2025-11-24 19:16:27 +00:00
parent 5484351523
commit 8765266dae
3 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -217,7 +217,8 @@ inline void State::mergeAttrs(AttrPath & attrPath, ExprSet * source, ExprSet * t
if (auto collision = target->attrs.find(insertKey);
collision != target->attrs.end()) // Attr already defined in target, error.
{
return dupAttr(insertKey, insertDef.pos, collision->second.pos);
attrPath.push_back(AttrName(insertDef.pos, insertKey));
return dupAttr(attrPath, insertDef.pos, collision->second.pos);
}
if (insertDef.kind == ExprAttrs::AttrDef::Kind::InheritedFrom) {
auto & sel = dynamic_cast<ExprSelect &>(*insertDef.e);
@@ -1,4 +1,4 @@
error: attribute 'z' already defined at /pwd/in.nix:2:3
error: attribute 'x.z' already defined at /pwd/in.nix:2:3
at /pwd/in.nix:3:16:
2| x.z = 3;
3| x = { y = 3; z = 3; };
@@ -1,4 +1,4 @@
error: attribute 'y' already defined at /pwd/in.nix:2:3
error: attribute 'x.y' already defined at /pwd/in.nix:2:3
at /pwd/in.nix:3:9:
2| x.y.y = 3;
3| x = { y.y= 3; z = 3; };