about summary refs log tree commit diff
path: root/src/libexpr/nixexpr.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-05-02T13·39+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-05-02T13·39+0000
commitdc719e6ba57fc877574bd3bc023a25676c555b3c (patch)
treec7a2351f4f0e3aa777ec2454167912ad9b5c8df7 /src/libexpr/nixexpr.cc
parentae55e79541ffbce7a051794d6d25e9e8c7b63b2d (diff)
* Some preliminaries towards NIX-45.
Diffstat (limited to 'src/libexpr/nixexpr.cc')
-rw-r--r--src/libexpr/nixexpr.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index aee57acb116e..05c1ee45ceea 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -226,6 +226,8 @@ Expr substitute(const ATermMap & subs, Expr e)
 {
     checkInterrupt();
 
+    //if (subs.size() == 0) return e;
+
     ATerm name, pos, e2;
 
     /* As an optimisation, don't substitute in subterms known to be
@@ -255,7 +257,7 @@ Expr substitute(const ATermMap & subs, Expr e)
             subs2.remove(name);
         }
         return makeFunction(
-            (ATermList) substitute(subs, (ATerm) formals),
+            (ATermList) substitute(subs2, (ATerm) formals),
             substitute(subs2, body), pos);
     }
 
@@ -327,13 +329,16 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e)
         ATermMap defs2(defs);
         for (ATermIterator i(formals); i; ++i) {
             Expr deflt;
-            if (!matchNoDefFormal(*i, name))
-                if (matchDefFormal(*i, name, deflt))
-                    checkVarDefs2(done, defs, deflt);
-                else
-                    abort();
+            if (!matchNoDefFormal(*i, name) &&
+                !matchDefFormal(*i, name, deflt))
+                abort();
             defs2.set(name, (ATerm) ATempty);
         }
+        for (ATermIterator i(formals); i; ++i) {
+            Expr deflt;
+            if (matchDefFormal(*i, name, deflt))
+                checkVarDefs2(done, defs2, deflt);
+        }
         checkVarDefs2(done, defs2, body);
     }