luaj.luajc icon indicating copy to clipboard operation
luaj.luajc copied to clipboard

Error running JVML-JIT

Open SquidDev opened this issue 7 years ago • 2 comments

This project

easm:159: Bad argument, Index expected, got nil
At: java.lang.System.<clinit>()V:23

Both on LuaJ and Cobalt versions

SquidDev avatar Oct 09 '16 08:10 SquidDev

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

SquidDev avatar Oct 09 '16 20:10 SquidDev

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)()

SquidDev avatar Oct 13 '16 16:10 SquidDev