lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I'm testing it against Lua from versions 5.1 to 5.4 but the call stack is inconsistent in newer versions while Lua 5.1 is showing the expected stack.
> 
> I wrote a simple reproducible test:
> 
> function mt:check(k)
>   local current = self.path[#self.path]
>   if type(current) ~= 'table' then
>     error('actually node is not a table',2)
>   end
>   table.insert(self.path, current[k])
>   return self
> end
> 
> local function check(t)
>   return setmetatable({path={t}}, mt)
> end
> 
> local list = {a = { b= 1 }}
> check(list) -- line 18
>   :check('a')
>     :check('b')
>       :check('c') -- line 21
> 
> It is expected that the call to ":check('c')" throws an error. This call is on line 21.

Thanks for the report. This is a bug.

Lua numbers lines not by statements, but by expressions. It usually tries
to use the line of the operator as the line of the expression. In the
case of function calls, the "operator" sould probably be the '('.
Consider the following examples:

  > load("print(a\n\n+\n3)")()
  [string "print(a..."]:3: attempt to perform arithmetic on a nil value (global 'a')
  > load("print(a\n\n(\n3))")()
  [string "print(a..."]:1: attempt to call a nil value (global 'a')

The first error is on line 3, where is the '+'. The second error should
be on line 3 too, where is the '('.

-- Roberto