andremm/typedlua

attempt to index local 't' (a nil value) in function 'isLiteral'

Closed this issue · 4 comments

Zash commented

This file:

local function w(filename : string, data : string) : boolean
	local scratch = filename .. "~";
	local fh, open_err = io.open(scratch, "w");
	if not fh then return false; end
	local write_ok, write_err = fh:write(data);
	if not write_ok then return false; end
	local close_ok, close_err = fh:close();
	if not close_ok then return false; end
	return true;
end

gives this traceback:

lua: ./typedlua/tltype.lua:40: attempt to index local 't' (a nil value)
stack traceback:
	./typedlua/tltype.lua:40: in function 'isLiteral'
	./typedlua/tltype.lua:45: in function 'isFalse'
	./typedlua/tlfilter.lua:64: in function 'f'
	./typedlua/tlfilter.lua:291: in function 'f'
	./typedlua/tlfilter.lua:291: in function 'filter'
	./typedlua/tlchecker.lua:550: in function 'apply_filters'
	./typedlua/tlchecker.lua:1451: in function <./typedlua/tlchecker.lua:1425>
	(...tail calls...)
	./typedlua/tlchecker.lua:1877: in function 'check_stms'
	./typedlua/tlchecker.lua:1895: in function 'check_block'
	./typedlua/tlchecker.lua:1271: in function <./typedlua/tlchecker.lua:1244>
	(...tail calls...)
	./typedlua/tlchecker.lua:1877: in function 'check_stms'
	./typedlua/tlchecker.lua:1946: in function 'typecheck'
	tlc:138: in main chunk
	[C]: in ?

git bisect says 5c80570 broke it.

Same issue.
There are 2 lines in tlfilter.filter_falsy where tltype.isFalse and tltype.isTrue are called without arguments (this causes an error). This:

lf[#lf+1] = tltype.False()
l[#l+1] = tltype.True()

seems to fix the problem, but I'm not sure I correctly understand the code.

Now there is a different error:

lua: ./typedlua/tltype.lua:246: attempt to index local 't1' (a boolean value)
stack traceback:
	./typedlua/tltype.lua:246: in function 'isUnion'
	./typedlua/tltype.lua:193: in function 'Union'
	./typedlua/tlfilter.lua:70: in function 'f'
	./typedlua/tlfilter.lua:291: in function 'f'
	./typedlua/tlfilter.lua:291: in function 'filter'
	./typedlua/tlchecker.lua:550: in function 'apply_filters'
	./typedlua/tlchecker.lua:1451: in function <./typedlua/tlchecker.lua:1425>
	(...tail calls...)
	./typedlua/tlchecker.lua:1877: in function 'check_stms'
	./typedlua/tlchecker.lua:1895: in function 'check_block'
	./typedlua/tlchecker.lua:1271: in function <./typedlua/tlchecker.lua:1244>
	(...tail calls...)
	./typedlua/tlchecker.lua:1877: in function 'check_stms'
	./typedlua/tlchecker.lua:1946: in function 'typecheck'
	./tlc:138: in main chunk
	[C]: in ?

Sorry, it was a stupid mistake, should be fixed now. Hey @andremm, we need to add a test case for these so there are no more regressions.

@Zash thanks for pointing out this issue, @Penguinum thanks for reminding us to fix that, and @mascarenhas thanks for fixing it!

I just pushed two test cases for avoiding regressions on this.