about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-05-16T15·56+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-05-16T15·56+0200
commit1b3a03f1610b714adca41637ccd85a8157e236ab (patch)
treecfffb0927fe7ecb37018b60ae88a80857f8dcb43 /src/libexpr/eval.cc
parent229567293c4e0f31bc8c79f69b2ff25f8f6e5147 (diff)
Show which function argument was unexpected
Fixes #116.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 2f0c7e5cd32f..551ed4ba501b 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -765,11 +765,15 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v)
         }
 
         /* Check that each actual argument is listed as a formal
-           argument (unless the attribute match specifies a `...').
-           TODO: show the names of the expected/unexpected
-           arguments. */
-        if (!fun.lambda.fun->formals->ellipsis && attrsUsed != arg.attrs->size()) 
-            throwTypeError("function at %1% called with unexpected argument", fun.lambda.fun->pos);
+           argument (unless the attribute match specifies a `...'). */
+        if (!fun.lambda.fun->formals->ellipsis && attrsUsed != arg.attrs->size()) {
+            /* Nope, so show the first unexpected argument to the
+               user. */
+            foreach (Bindings::iterator, i, *arg.attrs)
+                if (fun.lambda.fun->formals->argNames.find(i->name) == fun.lambda.fun->formals->argNames.end())
+                    throwTypeError("function at %1% called with unexpected argument `%2%'", fun.lambda.fun->pos, i->name);
+            abort(); // can't happen
+        }
     }
 
     nrFunctionCalls++;