> > debug.sethook(function(...) print(...) end, "l")
> > if false then
> > goto EXIT
> > A = 1
> > end
> > ::EXIT::
>
> The output is:
> line 3
> line 6
>
> I think it should be
> line 2
> line 6
This is not a bug. It's a consequence of an optimization introduced by
the compiler. Replace false by foo and see the difference.
After "false" is replaced with "foo" we still see the bug:
$ luac -l -p -
if foo then
goto EXIT
A=2
end
::EXIT::
main <stdin:0,0> (7 instructions at 0x25f7840)
0+ params, 2 slots, 1 upvalue, 0 locals, 3 constants, 0 functions
1 [1] VARARGPREP 0
2 [2] GETTABUP 0 0 0 ; _ENV "foo"
3 [2] TEST 0 1
4 [2] JMP 2 ; to 7
5 [2] JMP 1 ; to 7
6 [3] SETTABUP 0 1 2k ; _ENV "A" 2
7 [5] RETURN 0 1 1 ; 0 out
In the Lua script: the global "foo" is accessed at the first line.
In the bytecode: "GETTABUP _ENV foo" is marked as line #[2].