Skip to content

fix(bundle): prevent tail-call in entry module for proper stack trace#1678

Merged
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
dnrovs:master
Jan 23, 2026
Merged

fix(bundle): prevent tail-call in entry module for proper stack trace#1678
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
dnrovs:master

Conversation

@dnrovs
Copy link
Contributor

@dnrovs dnrovs commented Jan 22, 2026

No description provided.

@Perryvw
Copy link
Member

Perryvw commented Jan 22, 2026

I don't quite understand what this is trying to solve. Could you provide an example stack trace with and without your fix?

@dnrovs
Copy link
Contributor Author

dnrovs commented Jan 22, 2026

return require("Main", ...) is a tail call and lua optimizes tail calls and removes the caller's stack frame, so the traceback can omit the top level call

writing local ____entry = require("Main", ...) then return ____entry prevents tail call and the caller remains on the stack so tracebacks include the line where require was called

before:

/usr/bin/lua5.4: Main.lua:27: err
stack traceback:
	[C]: in function 'error'
	Main.lua:27: in upvalue 'c'
	Main.lua:30: in upvalue 'b'
	Main.lua:33: in local 'a'
	Main.lua:37: in local 'module'
	Main.lua:12: in function <Main.lua:5>
	(...tail calls...)
	[C]: in ?

after:

/usr/bin/lua5.4: Main.lua:27: err
stack traceback:
	[C]: in function 'error'
	Main.lua:27: in upvalue 'c'
	Main.lua:30: in upvalue 'b'
	Main.lua:33: in local 'a'
	Main.lua:37: in local 'module'
	Main.lua:12: in local 'require'
	Main.lua:41: in main chunk
	[C]: in ?

@Perryvw Perryvw merged commit 6fa24e8 into TypeScriptToLua:master Jan 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants