lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, 27 Aug 2023 09:46:07 -0700
Gé Weijers <ge@weijers.org> wrote:

> It'll be tricky to fix this because it is not known until runtime whether a
> function like 'pairs' returns a to-be-closed variable.
> Closing the to-be-closed variable before the return may make the loop
> variables inaccessible, introducing another problem.
> 
> -- 
> Gé

Wouldn't it be possible to allow tail-calls if a to-be-closed variable
is set to nil? Or does this introduce other runtime overhead?

Either way, I think the current behavior is somewhat surprising
(particularly because a program that worked on Lua 5.3 may fail to work
on Lua 5.4 if it relies on tail calls there).

If it can't be fixed, I would propose to document it better at least
(i.e. add an explicit note in section "3.4.10 Function Calls" that
generic for-loops implies a to-be-closed variable and thus prohibits
tail calls). Also section "8.1 Incompatibilities in the Language"
should mention this breaking behavior of Lua 5.4 in regard to tail
calls in loops.

Regards,
Jan Behrens