Skip to content

Commit

Permalink
Show which function argument was unexpected
Browse files Browse the repository at this point in the history
Fixes #116.
  • Loading branch information
edolstra committed May 16, 2013
1 parent 2295672 commit 1b3a03f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit 1b3a03f

Please sign in to comment.