From 85d13c8f93c8b251f5883d9b38051b33bab1ad3e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 14 Apr 2010 08:37:08 +0000 Subject: [PATCH] * 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. --- src/libexpr/eval.cc | 25 ++----------------------- src/libexpr/eval.hh | 2 -- 2 files changed, 2 insertions(+), 25 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); } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 0491fc481..eda081261 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -240,8 +240,6 @@ private: Value * lookupVar(Env * env, const Symbol & name); - Value * lookupWith(Env * env, const Symbol & name); - friend class ExprVar; friend class ExprAttrs; friend class ExprLet;