forked from lix-project/lix
Merge pull request #3965 from glittershark/fix-top-level-ellipsis
Pass all args when auto-calling a function with an ellipsis
This commit is contained in:
commit
f4d3b4fb76
|
@ -1299,12 +1299,23 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
|
||||||
Value * actualArgs = allocValue();
|
Value * actualArgs = allocValue();
|
||||||
mkAttrs(*actualArgs, fun.lambda.fun->formals->formals.size());
|
mkAttrs(*actualArgs, fun.lambda.fun->formals->formals.size());
|
||||||
|
|
||||||
for (auto & i : fun.lambda.fun->formals->formals) {
|
if (fun.lambda.fun->formals->ellipsis) {
|
||||||
Bindings::iterator j = args.find(i.name);
|
// If the formals have an ellipsis (eg the function accepts extra args) pass
|
||||||
if (j != args.end())
|
// all available automatic arguments (which includes arguments specified on
|
||||||
actualArgs->attrs->push_back(*j);
|
// the command line via --arg/--argstr)
|
||||||
else if (!i.def)
|
for (auto& v : args) {
|
||||||
throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
|
actualArgs->attrs->push_back(v);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise, only pass the arguments that the function accepts
|
||||||
|
for (auto & i : fun.lambda.fun->formals->formals) {
|
||||||
|
Bindings::iterator j = args.find(i.name);
|
||||||
|
if (j != args.end()) {
|
||||||
|
actualArgs->attrs->push_back(*j);
|
||||||
|
} else if (!i.def) {
|
||||||
|
throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actualArgs->attrs->sort();
|
actualArgs->attrs->sort();
|
||||||
|
|
Loading…
Reference in a new issue