@@ -1496,15 +1496,13 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
14961496
14971497 ExprLambda & lambda (*vCur.lambda ().fun );
14981498
1499- auto size = (!lambda.arg ? 0 : 1 ) + (lambda.hasFormals ? lambda.getFormals ().size () : 0 );
1499+ auto size = (!lambda.arg ? 0 : 1 ) + (lambda.getFormals () ? lambda.getFormals ()-> formals .size () : 0 );
15001500 Env & env2 (mem.allocEnv (size));
15011501 env2.up = vCur.lambda ().env ;
15021502
15031503 Displacement displ = 0 ;
15041504
1505- if (!lambda.hasFormals )
1506- env2.values [displ++] = args[0 ];
1507- else {
1505+ if (auto formals = lambda.getFormals ()) {
15081506 try {
15091507 forceAttrs (*args[0 ], lambda.pos , " while evaluating the value passed for the lambda argument" );
15101508 } catch (Error & e) {
@@ -1520,7 +1518,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
15201518 there is no matching actual argument but the formal
15211519 argument has a default, use the default. */
15221520 size_t attrsUsed = 0 ;
1523- for (auto & i : lambda. getFormals () ) {
1521+ for (auto & i : formals-> formals ) {
15241522 auto j = args[0 ]->attrs ()->get (i.name );
15251523 if (!j) {
15261524 if (!i.def ) {
@@ -1542,13 +1540,13 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
15421540
15431541 /* Check that each actual argument is listed as a formal
15441542 argument (unless the attribute match specifies a `...'). */
1545- if (!lambda. ellipsis && attrsUsed != args[0 ]->attrs ()->size ()) {
1543+ if (!formals-> ellipsis && attrsUsed != args[0 ]->attrs ()->size ()) {
15461544 /* Nope, so show the first unexpected argument to the
15471545 user. */
15481546 for (auto & i : *args[0 ]->attrs ())
1549- if (!lambda. hasFormal (i.name )) {
1547+ if (!formals-> has (i.name )) {
15501548 StringSet formalNames;
1551- for (auto & formal : lambda. getFormals () )
1549+ for (auto & formal : formals-> formals )
15521550 formalNames.insert (std::string (symbols[formal.name ]));
15531551 auto suggestions = Suggestions::bestMatches (formalNames, symbols[i.name ]);
15541552 error<TypeError>(
@@ -1564,6 +1562,9 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
15641562 unreachable ();
15651563 }
15661564 }
1565+ else {
1566+ env2.values [displ++] = args[0 ];
1567+ }
15671568
15681569 nrFunctionCalls++;
15691570 if (countCalls)
@@ -1747,22 +1748,23 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
17471748 }
17481749 }
17491750
1750- if (!fun.isLambda () || !fun.lambda ().fun ->hasFormals ) {
1751+ if (!fun.isLambda () || !fun.lambda ().fun ->getFormals () ) {
17511752 res = fun;
17521753 return ;
17531754 }
1755+ auto formals = fun.lambda ().fun ->getFormals ();
17541756
1755- auto attrs = buildBindings (std::max (static_cast <uint32_t >(fun. lambda (). fun -> nFormals ), args.size ()));
1757+ auto attrs = buildBindings (std::max (static_cast <uint32_t >(formals-> formals . size () ), args.size ()));
17561758
1757- if (fun. lambda (). fun ->ellipsis ) {
1759+ if (formals ->ellipsis ) {
17581760 // If the formals have an ellipsis (eg the function accepts extra args) pass
17591761 // all available automatic arguments (which includes arguments specified on
17601762 // the command line via --arg/--argstr)
17611763 for (auto & v : args)
17621764 attrs.insert (v);
17631765 } else {
17641766 // Otherwise, only pass the arguments that the function accepts
1765- for (auto & i : fun. lambda (). fun -> getFormals () ) {
1767+ for (auto & i : formals-> formals ) {
17661768 auto j = args.get (i.name );
17671769 if (j) {
17681770 attrs.insert (*j);
@@ -1782,6 +1784,7 @@ values, or passed explicitly with '--arg' or '--argstr'. See
17821784 }
17831785
17841786 callFunction (fun, allocValue ()->mkAttrs (attrs), res, pos);
1787+
17851788}
17861789
17871790void ExprWith::eval (EvalState & state, Env & env, Value & v)
0 commit comments