luaj.luajc
luaj.luajc copied to clipboard
Error running JVML-JIT
easm:159: Bad argument, Index expected, got nil
At: java.lang.System.<clinit>()V:23
Both on LuaJ and Cobalt versions
A minimal reproduction:
for i=1, 1 do
local ca
for v = 1, 1 do
if v then ca = v end
end
assert(ca);
(function() return ca end)()
end
It appears that the upvalue is being opened on the for loop, resulting in it being cleared each iteration. We either need to defer opening the variable or move opening to before the loop.
Currently
local ca
for v = 1, 1 do
-- Upvalue created here (and after the last iteration)
if v then ca = v end
end
assert(ca);
(function() return ca end)()
Ideally
local ca -- Upvalue created here
for v = 1, 1 do
if v then ca = v end
end
assert(ca);
-- Or here
(function() return ca end)()