franko / luajit-lang-toolkit

A Lua bytecode compiler written in Lua itself for didactic purposes or for new language implementations
Other
654 stars 91 forks source link

traceback inside a function literal used as a function argument reports wrong line numbers #34

Closed shviller closed 7 years ago

shviller commented 7 years ago
d:\>cat pcall-wrong-lineno.lua
pcall(function()
  print(debug.traceback())
end)

d:\>lua pcall-wrong-lineno.lua
stack traceback:
        pcall-wrong-lineno.lua:2: in function <pcall-wrong-lineno.lua:1>
        [C]: in function 'pcall'
        pcall-wrong-lineno.lua:1: in main chunk
        [C]: at 0x00402180

d:\>lua luajit-lang-toolkit\run.lua pcall-wrong-lineno.lua
stack traceback:
        pcall-wrong-lineno.lua:2: in function <pcall-wrong-lineno.lua:1>
        [C]: in function 'pcall'
        pcall-wrong-lineno.lua:3: in function 'fn'
        luajit-lang-toolkit\run.lua:73: in main chunk
        [C]: at 0x00402180

d:\>lua -v
LuaJIT 2.0.2 -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/

Doesn't have to be pcall specifically, and it seems it uses the last line of the function declaration, unlike Lua and LuaJIT, which use the line on which the outer function call occurs:

function call(_, fn)
  fn()
end

call(

"ignored",

function()
  print(debug.traceback())
end,

"also ignored"

)

Lua/LuaJIT report line 5 (where call is), luajit-lang-toolkit reports line 11 (where the function declaration ends).

franko commented 7 years ago

I think I have fixed the issue with the commit above. You may give a look if you want.

Thank you in any case for reporting the problem.

shviller commented 7 years ago

It seems it has indeed taken care of the bug. Thank you so much!