teal-language / tl

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

Stacktrace on 0.14 #551

Closed lewis6991 closed 2 years ago

lewis6991 commented 2 years ago

Hi, just installed the new release and ran it through my project and got this stacktrace:

/opt/homebrew/opt/lua@5.1/bin/lua5.1: ...lewrus01/.luarocks/share/lua/5.1/compat53/module.lua:179: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        ...lewrus01/.luarocks/share/lua/5.1/compat53/module.lua:179: in function 'ipairs'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:5534: in function 'is_valid_union'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:9036: in function 'cbkind_after'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3351: in function 'recurse'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3216: in function 'fn'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3342: in function 'recurse'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3160: in function 'fn'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3342: in function 'recurse'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3160: in function 'fn'
        ...
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3342: in function 'recurse'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3160: in function 'fn'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3342: in function </Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:3322>
        (tail call): ?
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:9418: in function 'type_check'
        /Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:9799: in function </Users/lewrus01/.luarocks/share/lua/5.1/tl.lua:9756>
        (tail call): ?
        .../.luarocks/lib/luarocks/rocks-5.1/tl/0.14.0-1/bin/tl:710: in function '?'
        .../.luarocks/lib/luarocks/rocks-5.1/tl/0.14.0-1/bin/tl:1410: in main chunk
        [C]: ?

I'm guessing there is just a missing nil check somewhere.

Hopefully this is enough but let me know if you need any more information.

hishamhm commented 2 years ago

@lewis6991 thanks for the report! unfortunately nothing springs to mind when I look at the offending line pointed by the stack trace. It looks like the data structure for a union type is being generated incorrectly, but I haven't made many changes to those recently, so it's unclear to me how that happened. Could you try to reduce a minimal test case that triggers this? Thanks!

hishamhm commented 2 years ago

Oh wait, I kept going further down the stack trace and I think I got it.

This is a minimal regression test:

local x: string | number = "hello" or "world"

I have a quick fix!

lewis6991 commented 2 years ago

To reproduce just checkout this repo (https://github.com/lewis6991/gitsigns.nvim) and run tl build (or make; it's a simple enough Makefile).

I can try and minimise this when I get a chance.