Repository navigation
Conversation
buyemune-sys
pushed a commit
to tarantool-contrib/go-moonscript
that referenced
this pull request
Nov 27, 2026
…nd long jumps Three bugs of the compiler, found by the fuzz test of the next commit and reachable from source in both dialects: - An assignment to a single local with more values than targets evaluated the first value into the local, before the others: in "i = 5, f(i)" f got the new i (lua5.1 and luajit pass the old one, 1). The value now goes to a temporary, as for a multiple assignment (yuin/gopher-lua#560). - A "..." value for a local's register, as in "x = (...)" or the case above with "i = ..., ...", was a VARARG into that register. The VM's VARARG sets the top of the stack after the values it loads and clears the registers above it, so the locals and temporaries above the target became Go nils: "local x, y = 1, 2; x = (...)" then reading y was a nil-pointer panic in the VM, and the compileExpr result was negative (-1 registers), so the next value was compiled over a live register. It is loaded into a free register and moved. - A jump over more instructions than an instruction addresses was checked for forward jumps only: the backward jump of a repeat loop and a numeric for's FORPREP and FORLOOP over a body of more than 131071 instructions jumped out of the code (index out of range in the VM). They are lua5.1's "control structure too long", now at the jump's line (it was "too long to jump." at the function's first line, line 0 for the main chunk). Under DialectLuaJIT the parser's model of LuaJIT's code generator finds them first in source. A function with more than 262143 closures (CLOSURE's Bx) is "constant table overflow", lua5.1's. Tests: testdata/compat/compile_assign_extra.lua (lua5.1 ref), TestCompileLongJumps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #440 .
I ran into this in Rex, a terminal app whose Lua config runs on gopher-lua v1.1.2: a helper in my config doing
url, closes = url:sub(1, -2), closes - 1crashed with a nil pointer dereference. Tracking that down led here.Changes proposed in this pull request:
a, b = b, agive1, 1, and madeu, c = u:sub(1, -2), c - 1crash with a nil pointer dereference: the method lookup overwroteubefore the call read it.s.x, d = d, 7stores the newd. Constants can still stand in for values (PropagateK), since nothing can overwrite them.g, t.x = 5, ksetgto"x"._lua5.1-tests/attrib.lua, which passes now, and adds-- issue #440cases to_glua-tests/issues.lua.Every change applies only when there's more than one target, so single-target assignments compile as before.
How I checked it:
make buildleaves the generated files unchanged, andgo test ./...passes. The new tests fail without the compiler change.and/or, each run under this branch and under PUC Lua 5.1.5, comparing every variable afterwards. All 9,000 match. Master differs from Lua 5.1.5 on 1,641 of them. Happy to share the fuzz script.This touches the same line in
compileAssignStmtLeftas #538. They should fit together: #538 changes the single-target path, and this only changes the multi-target one.I worked this out with help from Claude Code. I've reviewed the change, and the checks above were run as described.