* Change the scoping of "inherit (e) ..." in recs so that the
attributes of the rec are in scope of `e'. This is useful in expressions such as rec { lib = import ./lib; inherit (lib) concatStrings; } It does change the semantics of expressions such as let x = {y = 1;}; in rec { x = {y = 2;}; inherit (x) y; }.y This now returns 2 instead of 1. However, no code in Nixpkgs or NixOS seems to rely on the old behaviour.
This commit is contained in:
parent
d407d572fd
commit
a64bbe049e
3 changed files with 10 additions and 2 deletions
|
@ -91,12 +91,13 @@ static Expr fixAttrs(bool recursive, ATermList as)
|
||||||
if (matchInherit(*i, src, names, pos)) {
|
if (matchInherit(*i, src, names, pos)) {
|
||||||
bool fromScope = matchScope(src);
|
bool fromScope = matchScope(src);
|
||||||
for (ATermIterator j(names); j; ++j) {
|
for (ATermIterator j(names); j; ++j) {
|
||||||
Expr rhs = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
|
||||||
if (attrs.children.find(*j) != attrs.children.end())
|
if (attrs.children.find(*j) != attrs.children.end())
|
||||||
throw ParseError(format("duplicate definition of attribute `%1%' at %2%")
|
throw ParseError(format("duplicate definition of attribute `%1%' at %2%")
|
||||||
% showAttrPath(ATmakeList1(*j)) % showPos(pos));
|
% showAttrPath(ATmakeList1(*j)) % showPos(pos));
|
||||||
Tree & t(attrs.children[*j]);
|
Tree & t(attrs.children[*j]);
|
||||||
t.leaf = rhs; t.pos = pos; if (recursive) t.recursive = false;
|
t.leaf = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
||||||
|
t.pos = pos;
|
||||||
|
if (recursive && fromScope) t.recursive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
tests/lang/eval-okay-scope-7.exp
Normal file
1
tests/lang/eval-okay-scope-7.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Int(1)
|
6
tests/lang/eval-okay-scope-7.nix
Normal file
6
tests/lang/eval-okay-scope-7.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
rec {
|
||||||
|
inherit (x) y;
|
||||||
|
x = {
|
||||||
|
y = 1;
|
||||||
|
};
|
||||||
|
}.y
|
Loading…
Reference in a new issue