confusing error message

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 2 Aug 2012 21:37:33 +0100

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

Other related posts: