about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-04-14T08·37+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-04-14T08·37+0000
commit85d13c8f93c8b251f5883d9b38051b33bab1ad3e (patch)
tree36727b29c68785d7060dca66229798b71505c182 /src/libexpr
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')
-rw-r--r--src/libexpr/eval.cc25
-rw-r--r--src/libexpr/eval.hh2
2 files changed, 2 insertions, 25 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 0505c5b2420c..d8acdcb6f6e3 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 0491fc481f03..eda081261c39 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;