Re: confusing error message

  • From: Coda Highland <chighland@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 2 Aug 2012 13:41:47 -0700

On Thu, Aug 2, 2012 at 1:37 PM, Justin Cormack
<justin@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Running the following (buggy!) program (with git head)
>
>
> local ffi = require "ffi"
> local bit = require "bit"
>
> local ui = ffi.typeof("uint32_t")
>
> local function test(a, b)
>   return bit.band(a, ui(b))
> end
>
> local function other()
>   local a = 5
>   local b = 6
>   print(test(a, b))
> end
>
> other()
>
>
> Gives the error
>
> luajit: tmp.lua:13: bad argument #2 to 'test' (number expected, got cdata)
> stack traceback:
>         [C]: in function 'test'
>         tmp.lua:13: in function 'other'
>         tmp.lua:16: in main chunk
>         [C]: ?
>
> Which is very confusing as the error is not on line 13 (print(test(a,
> b)) where there is no cdata it is on line 7 when b is converted to a
> cdata which the bit library can't deal with. Looks like an
> optimisation confuses the error reporting.
>
> Justin
>

Backtrace looks right to me. It's reporting that the error is in
function "test" while executing C code (that is to say, the conversion
routine). It got inlined, yes, but this is still in-line with the
output I would expect. Even vanilla Lua doesn't track an "exact" stack
trace when it does optimizations (tail calls, for example).

/s/ Adam

Other related posts: