teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.02k stars 101 forks source link

[next branch] Attempt to index nil value `t` #736

Closed Frityet closed 5 months ago

Frityet commented 5 months ago

Trace:

lua: teal///tl.lua:6312: attempt to index a nil value (local 't')
stack traceback:
        teal///tl.lua:6312: in upvalue 'is_unknown'
        teal///tl.lua:8596: in method 'resolve_for_call'
        teal///tl.lua:10804: in local 'bs'
        teal///tl.lua:4430: in upvalue 'extra_callback'
        teal///tl.lua:4600: in local 'fn'
        teal///tl.lua:4666: in upvalue 'recurse'
        teal///tl.lua:4462: in local 'fn'
        teal///tl.lua:4666: in upvalue 'recurse'
        teal///tl.lua:4547: in local 'fn'
        teal///tl.lua:4666: in upvalue 'recurse'
        ...     (skipping 16 levels)
        teal///tl.lua:4666: in upvalue 'recurse'
        teal///tl.lua:4586: in local 'fn'
        teal///tl.lua:4666: in upvalue 'recurse'
        teal///tl.lua:4462: in local 'fn'
        teal///tl.lua:4666: in function <teal///tl.lua:4641>
        (...tail calls...)
        teal///tl.lua:12373: in function 'tl.type_check'
        teal///tl.lua:12551: in function <teal///tl.lua:12527>
        [C]: in function 'require'
        get-ast.tl:19: in main chunk
        (...tail calls...)
        teal//tl:957: in main chunk
        [C]: in ?

This is running on Lua 5.4 on MacOS.

Trying to run tl gen instead of tl run results in this trace:

lua: teal//tl:240: attempt to index a nil value (local 'result')
stack traceback:
        teal//tl:240: in upvalue 'process_module'
        teal//tl:798: in field '?'
        teal//tl:957: in main chunk
        [C]: in ?

Offending code:

local tl = require("tl")
local pretty = require("pl.pretty")

local input_file, output_file = arg[1], arg[2] or "ast.lua"
if not input_file then error("Missing input file as first argument") end

local f = assert(io.open(input_file, "rb"))
local ast, errors, modules = tl.parse(f:read("*a"), input_file)
f:close()

if #errors > 0 then
  for _, err in ipairs(errors) do
    io.stderr:write(string.format("%s:%d:%d: %s\n", input_file, err.y, err.x, err.msg))
  end
  os.exit(1)
end

local f = assert(io.open(output_file, "w+b"))
f:write("return ", pretty.write(ast as table))
f:close()

Running with 0.15.3 works, and this isn't a big deal cause it does work on the main branch, but I just thought it would be important to report

hishamhm commented 5 months ago

Hi, thanks for reporting! Yes, reports of failures in the next branch are especially welcome!

hishamhm commented 5 months ago

minimal repro (must be saved with .lua extension)

local mypairs = function(t)
end

for k, v in mypairs(t) do
    print(k, v)
end
hishamhm commented 5 months ago

also reproducible in .tl mode as:

local function f()
end

for k, v in f(t) do
end
hishamhm commented 5 months ago

Should be fixed now! Thank you for reporting!!

Frityet commented 5 months ago

Thank you so much!