Skip to content

Commit

Permalink
Fix parsing issues with or operator
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Dec 21, 2024
1 parent 0eaf57a commit b87f7ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/luacode/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (p *parser) codePostfix(fs *funcState, operator binaryOperator, e1, e2 expr
}
return e2, nil
case binaryOperatorOr:
if e1.t != noJump {
if e1.f != noJump {
return voidExpression(), errors.New("internal error: codePostfix: list should have been closed by codeInfix")
}
var err error
Expand Down Expand Up @@ -1105,7 +1105,7 @@ func (p *parser) toRegister(fs *funcState, e expressionDescriptor, reg registerI
if err := fs.patchList(e.f, final, reg, positionLoadFalse); err != nil {
return e, err
}
if err := fs.patchList(e.f, final, reg, positionLoadTrue); err != nil {
if err := fs.patchList(e.t, final, reg, positionLoadTrue); err != nil {
return e, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/luacode/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (p *parser) enterBlock(fs *funcState, isLoop bool) *blockControl {

// closeFunction finalizes a [funcState] so that its [Prototype] is usable.
//
// Equivalent to `open_func` in upstream Lua.
// Equivalent to `close_func` in upstream Lua.
func (p *parser) closeFunction(fs *funcState) error {
p.codeReturn(fs, p.numVariablesInStack(fs), 0)
if err := p.leaveBlock(fs); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/luacode/testdata/TailCall/input.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local function factorial(n, acc)
acc = acc or 1
if n == 0 then return acc end
return factorial(n - 1, acc * n)
end

return factorial(3)
Binary file added internal/luacode/testdata/TailCall/luac.out
Binary file not shown.

0 comments on commit b87f7ed

Please sign in to comment.