From 0f5bdeaeba0f04e49c47f4a2be55b14185a7dfdd Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 26 Jul 2022 18:05:23 +0800 Subject: fix missing checks and issues related to destrucuring in if branches. --- spec/inputs/assign.yue | 50 +++++++++++++++++++++++-- spec/inputs/cond.yue | 2 +- spec/inputs/global.yue | 4 +- spec/inputs/metatable.yue | 2 +- spec/inputs/using.yue | 7 ++++ spec/outputs/assign.lua | 93 ++++++++++++++++++++++++++++++++++++++++++++-- spec/outputs/cond.lua | 2 +- spec/outputs/global.lua | 4 +- spec/outputs/metatable.lua | 2 +- spec/outputs/using.lua | 7 ++++ 10 files changed, 159 insertions(+), 14 deletions(-) (limited to 'spec') diff --git a/spec/inputs/assign.yue b/spec/inputs/assign.yue index dac2ba3..d04bcb8 100644 --- a/spec/inputs/assign.yue +++ b/spec/inputs/assign.yue @@ -8,20 +8,20 @@ _ = -> a,b,c,d = 1,2,3,4 - hello[232], (5+5)[121], hello, x[99] = 100, 200, 300 + hello[232], (5+5)[121], hello, x[99] = 100, 200, 300, 400 joop = 12 joop = 2345 a, b = if hello - "hello" + "hello", nil else "nothing", "yeah" a, b = if hello - if yeah then "one", "two" else "mmhh" + if yeah then "one", "two" else "mmhh", nil else print "the other" "nothing", "yeah" @@ -31,3 +31,47 @@ c, d = 1, 2 if true x = (do f! 123) if f = getHandler! + +(using nil) <- _ + +a.# = do + print 123 + {} + +do + {a, b} = switch c + when "a" + tb + when "b" + f! + +a[] = if x + 1 +else + 2 + +do + a, b[] = if x + switch y + when 1 + f! + +do + a, {b} = if x + f! + else + 123, tb + +do + a, b[], c, d.add# = if x + switch y + when 1 + f! + elseif x2 + if y2 + f1! + else + print "hello" + do + print 123 + 1, f2! diff --git a/spec/inputs/cond.yue b/spec/inputs/cond.yue index 773ef91..9981e93 100644 --- a/spec/inputs/cond.yue +++ b/spec/inputs/cond.yue @@ -158,7 +158,7 @@ do ---------------- a = 12 -a,c,b = "cool" if something +a,c,b = "cool", nil, nil if something diff --git a/spec/inputs/global.yue b/spec/inputs/global.yue index 7d6cfde..59cf764 100644 --- a/spec/inputs/global.yue +++ b/spec/inputs/global.yue @@ -1,6 +1,6 @@ do - global a,b,c = 223, 343 + global a,b,c = 223, 343, nil global cool = "dad" do @@ -9,7 +9,7 @@ do do global a,b,c - a,b,c,d = "hello" + a,b,c,d = "hello", nil, nil, nil do diff --git a/spec/inputs/metatable.yue b/spec/inputs/metatable.yue index 7e9b4f2..86991c2 100644 --- a/spec/inputs/metatable.yue +++ b/spec/inputs/metatable.yue @@ -24,7 +24,7 @@ do x.abc, a.b.# = 123, {} func!.# = mt --, extra -a, b.c.#, d, e = 1, mt, "abc" +a, b.c.#, d, e = 1, mt, "abc", nil is_same = a.#.__index == a.index# diff --git a/spec/inputs/using.yue b/spec/inputs/using.yue index 9944b60..31afaab 100644 --- a/spec/inputs/using.yue +++ b/spec/inputs/using.yue @@ -20,3 +20,10 @@ _ = (a,e,f using a,b,c, hello) -> _ = (using nil) -> hello or= 2 + +do + a = {} + (using nil) <- _ + {x, y} = a + +nil diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua index 628f763..c7f2e20 100644 --- a/spec/outputs/assign.lua +++ b/spec/outputs/assign.lua @@ -7,14 +7,14 @@ _ = function() local a, b, c a, b, c, d = 1, 2, 3, 4 local hello - hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300 + hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300, 400 joop = 12 end end local joop = 2345 local a, b if hello then - a, b = "hello" + a, b = "hello", nil else a, b = "nothing", "yeah" end @@ -22,7 +22,7 @@ if hello then if yeah then a, b = "one", "two" else - a, b = "mmhh" + a, b = "mmhh", nil end else print("the other") @@ -42,3 +42,90 @@ do end)()) end end +return _(function() + setmetatable(a, (function() + print(123) + return { } + end)()) + do + local a, b + if "a" == c then + do + local _obj_0 = tb + a, b = _obj_0[1], _obj_0[2] + end + elseif "b" == c then + do + local _obj_0 = f() + a, b = _obj_0[1], _obj_0[2] + end + end + end + if x then + a[#a + 1] = 1 + else + a[#a + 1] = 2 + end + do + local a + if x then + do + local _exp_0 = y + if 1 == _exp_0 then + do + local _obj_0, _obj_1 = f() + b[#b + 1] = _obj_1 + a = _obj_0 + end + end + end + end + end + do + local a + local b + if x then + do + local _obj_0, _obj_1 = f() + a = _obj_0 + b = _obj_1[1] + end + else + a = 123 + b = tb[1] + end + end + do + local a, c + if x then + do + local _exp_0 = y + if 1 == _exp_0 then + do + local _obj_0, _obj_1, _obj_2, _obj_3 = f() + b[#b + 1] = _obj_1 + a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3 + end + end + end + elseif x2 then + if y2 then + do + local _obj_0, _obj_1, _obj_2, _obj_3 = f1() + b[#b + 1] = _obj_1 + a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3 + end + end + else + print("hello") + do + print(123) + do + local _obj_0, _obj_1, _obj_2 = f2() + b[#b + 1] = _obj_0 + a, c, getmetatable(d).__add = 1, _obj_1, _obj_2 + end + end + end + end +end) diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index 178bf9b..7764439 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua @@ -251,7 +251,7 @@ end local a = 12 local c, b if something then - a, c, b = "cool" + a, c, b = "cool", nil, nil end local j if 1 then diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index ef73823..930ecf6 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua @@ -1,5 +1,5 @@ do - a, b, c = 223, 343 + a, b, c = 223, 343, nil cool = "dad" end do @@ -29,7 +29,7 @@ do end do local d - a, b, c, d = "hello" + a, b, c, d = "hello", nil, nil, nil end do local What diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua index 2d72e1d..6f5ceed 100644 --- a/spec/outputs/metatable.lua +++ b/spec/outputs/metatable.lua @@ -66,7 +66,7 @@ setmetatable(a.b, { }) x.abc = 123 setmetatable(func(), mt) setmetatable(b.c, mt) -a, d, e = 1, "abc" +a, d, e = 1, "abc", nil local is_same = getmetatable(a).__index == getmetatable(a).__index setmetatable(a, { __index = tb diff --git a/spec/outputs/using.lua b/spec/outputs/using.lua index 6d0d888..ff23a30 100644 --- a/spec/outputs/using.lua +++ b/spec/outputs/using.lua @@ -21,3 +21,10 @@ end _ = function() local hello = hello or 2 end +do + local a = { }; + _(function() + local x, y = a[1], a[2] + end) +end +return nil -- cgit v1.2.3-55-g6feb