From f7150a004e26f446fbf7a47bae368f209248fa67 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 26 Jul 2022 11:34:34 +0800 Subject: make destructuring work on function multiple returned values, fix `a, b[] = 1` crashing issue, no longer support implicit declaring variable to be nil. --- spec/inputs/destructure.yue | 8 ++++++-- spec/inputs/local.yue | 2 +- spec/inputs/syntax.yue | 2 +- spec/outputs/destructure.lua | 21 +++++++++++++++++++++ spec/outputs/local.lua | 2 +- spec/outputs/syntax.lua | 2 +- 6 files changed, 31 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 24282c0..53f9ea3 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue @@ -12,7 +12,7 @@ do {:a,:b,:c,:d} = yeah {a}, b = one, two - {b}, c = one + {b}, c = one, nil {d}, e = one, two x, {y} = one, two @@ -22,7 +22,7 @@ do {a, :b, c, :d, e, :f, g} = tbl - do :a, :b, c = tbl + do :a, :b, c = tbl, nil do a, :b, :c = tbl, _ @@ -187,3 +187,7 @@ do do const :width, :height = View.size const {:x = 0.0, :y = 0.0} = point + +do + x1, x2, x3, a[], d, {b}, e, c.# = 1, 2, 3, f! + y1, :y2, :y3, y4 = f1!, f2! diff --git a/spec/inputs/local.yue b/spec/inputs/local.yue index 8e04742..a801fb7 100644 --- a/spec/inputs/local.yue +++ b/spec/inputs/local.yue @@ -3,7 +3,7 @@ do local a local a,b,c - b,g = 23232 + b,g = 23232,nil do diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index d18bd0e..e274f1a 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue @@ -2,7 +2,7 @@ a = 1 + 2* 3 / 6 -a, bunch, go, here = another, world +a, bunch, go, here = another, world, nil, nil func arg1, arg2, another, arg3 diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 59ee358..dfac42c 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua @@ -407,3 +407,24 @@ do end end end +do + local x1, x2, x3, d, e + local b + do + local _obj_0, _obj_1, _obj_2, _obj_3, _obj_4 = f() + do + local _obj_5 = a + _obj_5[#_obj_5 + 1] = _obj_0 + end + setmetatable(c, _obj_4) + x1, x2, x3, d, e = 1, 2, 3, _obj_1, _obj_3 + b = _obj_2[1] + end + local y1, y4 + local y2, y3 + do + local _obj_0, _obj_1 = f2() + y1, y4 = f1(), _obj_1 + y2, y3 = _obj_0.y2, _obj_0.y3 + end +end diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua index 524d9ef..5004e75 100644 --- a/spec/outputs/local.lua +++ b/spec/outputs/local.lua @@ -2,7 +2,7 @@ do local a local a, b, c local g - b, g = 23232 + b, g = 23232, nil end do local x = 1212 diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index a4cb8e2..22b6b80 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua @@ -1,6 +1,6 @@ local a = 1 + 2 * 3 / 6 local bunch, go, here -a, bunch, go, here = another, world +a, bunch, go, here = another, world, nil, nil func(arg1, arg2, another, arg3) local we here, we = function() end, yeah -- cgit v1.2.3-55-g6feb