Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler bug: fails on "for k,v in global_table.pairs(t)" #510

Open
ewmailing opened this issue Jan 6, 2022 · 0 comments
Open

Compiler bug: fails on "for k,v in global_table.pairs(t)" #510

ewmailing opened this issue Jan 6, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ewmailing
Copy link

I found a bug with the Pallene compiler when trying to use a for in loop with a pairs function.
In my case, the pairs function was passed into Pallene from Lua and stored in a global table.

It seems that Pallene can't handle the g_luaFuncs. part

	for k,v in g_luaFuncs.pairs(t) do

	end

It gives the traceback:

lua: ./pallene/to_ir.lua:364: attempt to index a nil value (field '_def')
stack traceback:
	./pallene/to_ir.lua:364: in method 'convert_stat'
	./pallene/to_ir.lua:308: in method 'convert_stats'
	./pallene/to_ir.lua:317: in method 'convert_stat'
	./pallene/to_ir.lua:730: in method 'convert_func'
	./pallene/to_ir.lua:693: in method 'convert_stat'
	./pallene/to_ir.lua:271: in function <./pallene/to_ir.lua:219>
	(...tail calls...)
	[C]: in function 'xpcall'
	./pallene/trycatch.lua:64: in function 'pallene.trycatch.pcall'
	./pallene/to_ir.lua:46: in function 'pallene.to_ir.convert'
	./pallene/driver.lua:83: in function 'pallene.driver.compile_internal'
	./pallene/driver.lua:107: in local 'f'
	./pallene/driver.lua:207: in function 'pallene.driver.compile'
	./pallenec:48: in local 'compile'
	./pallenec:130: in main chunk
	[C]: in ?

This only happens with the C generation, while --emit-lua does not have a problem.

As a workaround, Pallene can handle this:

	-- Pallene can handle this:
	local my_pairs = g_luaFuncs.pairs
	for k,v in my_pairs(t) do

	end

parse_pairs_bug.pln.txt

Attached is a complete .pln module to test against.

@hugomg hugomg added the bug Something isn't working label Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants