aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-04-14 08:37:08 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-04-14 08:37:08 +0000
commit85d13c8f93c8b251f5883d9b38051b33bab1ad3e (patch)
tree36727b29c68785d7060dca66229798b71505c182 /src/libexpr/eval.cc
parent816f9c0f6fae0229961bb573dfa0f75ff42c14eb (diff)
* Change the semantics of "with" so that inner "withs" take
precedence, i.e. `with {x=1;}; with {x=2;}; x' evaluates to 2'. This has a simpler implementation and seems more natural. There doesn't seem to be any code in Nixpkgs or NixOS that relies on the old behaviour.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 0505c5b24..d8acdcb6f 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -232,19 +232,6 @@ void mkPath(Value & v, const char * s)
}
-Value * EvalState::lookupWith(Env * env, const Symbol & name)
-{
- if (!env) return 0;
- Value * v = lookupWith(env->up, name);
- if (v) return v;
- Bindings::iterator i = env->bindings.find(sWith);
- if (i == env->bindings.end()) return 0;
- Bindings::iterator j = i->second.attrs->find(name);
- if (j != i->second.attrs->end()) return &j->second;
- return 0;
-}
-
-
Value * EvalState::lookupVar(Env * env, const Symbol & name)
{
/* First look for a regular variable binding for `name'. */
@@ -254,22 +241,14 @@ Value * EvalState::lookupVar(Env * env, const Symbol & name)
}
/* Otherwise, look for a `with' attribute set containing `name'.
- Outer `withs' take precedence (i.e. `with {x=1;}; with {x=2;};
- x' evaluates to 1). */
- Value * v = lookupWith(env, name);
- if (v) return v;
-
- /* Alternative implementation where the inner `withs' take
- precedence (i.e. `with {x=1;}; with {x=2;}; x' evaluates to
- 2). */
-#if 0
+ Inner `withs' take precedence (i.e. `with {x=1;}; with {x=2;};
+ x' evaluates to 2). */
for (Env * env2 = env; env2; env2 = env2->up) {
Bindings::iterator i = env2->bindings.find(sWith);
if (i == env2->bindings.end()) continue;
Bindings::iterator j = i->second.attrs->find(name);
if (j != i->second.attrs->end()) return &j->second;
}
-#endif
throwEvalError("undefined variable `%1%'", name);
}