You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error detected while processing /Users/joomy/work/vim9jit/ex/bug.vim:
line 3:
E5108: Error executing lua ./bug.lua:19: attempt to call local 'Foo' (a nil value)
stack traceback:
./bug.lua:19: in function 'autoload'
[string "luaeval()"]:1: in main chunk
(line 19 is the print(Foo(10)) line)
Given how ternary is implemented in _vim9script.lua, as long as the inputs to ternary are functions, they are called with no arguments:
But even without that, even an identifier can evaluate to a function, which will make type(if_true) == 'function' true in the ternary implementation in Lua. This identifier can come from outside, so you cannot determine whether a term has side effects syntactically.
The solution seems to be making ternary expression generation wrap the branches in function() return .. end all the time. (Lua doesn't seem to have lazy and/or either so that also doesn't work).
The text was updated successfully, but these errors were encountered:
Consider the following vim9script code:
(this returns 10 in Vim 9)
This is currently compiled into this Lua code:
... which throws an error for me:
(line 19 is the
print(Foo(10))
line)Given how
ternary
is implemented in_vim9script.lua
, as long as the inputs to ternary are functions, they are called with no arguments:vim9jit/lua/_vim9script.lua
Lines 14 to 28 in af7d608
And the "suspender" functions are only used if the branches of the ternary expressions have side effects:
vim9jit/crates/vim9-gen/src/lib.rs
Lines 1275 to 1294 in af7d608
and lambda expressions are considered not to have side effects:
vim9jit/crates/vim9-gen/src/lib.rs
Line 1249 in af7d608
But even without that, even an identifier can evaluate to a function, which will make
type(if_true) == 'function'
true in theternary
implementation in Lua. This identifier can come from outside, so you cannot determine whether a term has side effects syntactically.The solution seems to be making ternary expression generation wrap the branches in
function() return .. end
all the time. (Lua doesn't seem to have lazyand
/or
either so that also doesn't work).The text was updated successfully, but these errors were encountered: