Skip to content

Commit

Permalink
Fix yuin#315
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin authored and CMA2401PT committed Jul 18, 2024
1 parent c606e6b commit 64304cd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
41 changes: 41 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,44 @@ function test()
assert(2 % 2 == 0)
end
test()

-- issue #355
function test()
local x = "valid"
assert(x == "valid")
assert(zzz == nil)
x = zzz and "not-valid" or x
assert(x == "valid")
end
test()

function test()
local x = "valid"
local z = nil
assert(x == "valid")
assert(z == nil)
x = z and "not-valid" or x
assert(x == "valid")
end
test()

function test()
local x = "valid"
assert(x == "valid")
assert(zzz == nil)
x = zzz and "not-valid" or "still " .. x
assert(x == "still valid")
end
test()

-- issue #315
function test()
local a = {}
local d = 'e'
local f = 1

f, a.d = f, d

assert(f..", "..a.d == "1, e")
end
test()
7 changes: 2 additions & 5 deletions compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ func compileStmt(context *funcContext, stmt ast.Stmt) { // {{{
func compileAssignStmtLeft(context *funcContext, stmt *ast.AssignStmt) (int, []*assigncontext) { // {{{
reg := context.RegTop()
acs := make([]*assigncontext, 0, len(stmt.Lhs))
for i, lhs := range stmt.Lhs {
islast := i == len(stmt.Lhs)-1
for _, lhs := range stmt.Lhs {
switch st := lhs.(type) {
case *ast.IdentExpr:
identtype := getIdentRefType(context, context, st)
Expand All @@ -555,9 +554,7 @@ func compileAssignStmtLeft(context *funcContext, stmt *ast.AssignStmt) (int, []*
case ecUpvalue:
context.Upvalues.RegisterUnique(st.Value)
case ecLocal:
if islast {
ec.reg = context.FindLocalVar(st.Value)
}
ec.reg = context.FindLocalVar(st.Value)
}
acs = append(acs, &assigncontext{ec, 0, 0, false, false})
case *ast.AttrGetExpr:
Expand Down

0 comments on commit 64304cd

Please sign in to comment.