From 6af288657f5a7c43570ffbe91e1b727a4af5362d Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 29 Sep 2024 16:45:06 +0800 Subject: Disallowed some semantically incorrect syntax to improve code consistency. --- spec/inputs/upvalue_func.yue | 13 ++-- spec/outputs/5.1/attrib.lua | 144 ++++++++++++++++++------------------------- 2 files changed, 68 insertions(+), 89 deletions(-) (limited to 'spec') diff --git a/spec/inputs/upvalue_func.yue b/spec/inputs/upvalue_func.yue index d4b3273..378bf60 100644 --- a/spec/inputs/upvalue_func.yue +++ b/spec/inputs/upvalue_func.yue @@ -208,20 +208,21 @@ GameEngine\schedule (deltaTime) -> -- closure 1 -- test cases from issue do buff_strength = (char, item) -> - item.buffer.strength? char.stats.strength?::ref() + item.buffer.strength? char.stats.strength?::ref! local debug_env_before, debug_env_after exe_func = (func, env) -> ok, ... = try - debug_env_before(env) - func(env) - debug_env_after(env) + debug_env_before env + func env + debug_env_after env catch ex -- accessing ex and error error ex - return ex + -- implicit return + ex if ok return ... else - os.exit(1) + os.exit 1 diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua index c48c72c..dc1285c 100644 --- a/spec/outputs/5.1/attrib.lua +++ b/spec/outputs/5.1/attrib.lua @@ -44,18 +44,6 @@ do } a, b = _obj_0[1], _obj_0[2] end -local _anon_func_0 = function(_close_1, error, f, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_1(f) - if _ok_0 then - return ... - else - return error(...) - end - end -end -local _anon_func_1 = function() end do local v if flag then @@ -82,28 +70,17 @@ do f = _with_0 end local _close_1 = assert(getmetatable(f).__close) - return _anon_func_0(_close_1, error, f, pcall(_anon_func_1)) + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_1(f) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() end)) end)) end -local _anon_func_2 = function(_close_1, d, error, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_1(d) - if _ok_0 then - return ... - else - return error(...) - end - end -end -local _anon_func_3 = function(a, b) - if a ~= nil then - return a - else - return b - end -end -local _anon_func_4 = function() end do local a if true then @@ -133,37 +110,29 @@ do end end local d - if _anon_func_3(a, b) then + if (function() + if a ~= nil then + return a + else + return b + end + end)() then d = { value = value } end local _close_1 = assert(getmetatable(d).__close) - return _anon_func_2(_close_1, d, error, pcall(_anon_func_4)) + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_1(d) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() end)) end)) end -local _anon_func_5 = function(_, _close_1, error, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_1(_) - if _ok_0 then - return ... - else - return error(...) - end - end -end -local _anon_func_6 = function(_, _close_2, error, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_2(_) - if _ok_0 then - return ... - else - return error(...) - end - end -end do local _ do @@ -187,14 +156,30 @@ do end }) local _close_1 = assert(getmetatable(_).__close) - return _anon_func_5(_, _close_1, error, pcall(function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_1(_) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() local _ = setmetatable({ }, { __close = function() return print("first") end }) local _close_2 = assert(getmetatable(_).__close) - return _anon_func_6(_, _close_2, error, pcall(function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_2(_) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() return print("third") end)) end)) @@ -211,29 +196,6 @@ def = function(item) _defers[#_defers + 1] = item return _defers end -local _anon_func_7 = function(_, _close_1, error, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_1(_) - if _ok_0 then - return ... - else - return error(...) - end - end -end -local _anon_func_8 = function(_, _close_2, error, _arg_0, ...) - do - local _ok_0 = _arg_0 - _close_2(_) - if _ok_0 then - return ... - else - return error(...) - end - end -end -local _anon_func_9 = function() end do local _ = def(function() return print(3) @@ -252,12 +214,28 @@ do return print(2) end) local _close_1 = assert(getmetatable(_).__close) - return _anon_func_7(_, _close_1, error, pcall(function() + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_1(_) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() local _ = def(function() return print(1) end) local _close_2 = assert(getmetatable(_).__close) - return _anon_func_8(_, _close_2, error, pcall(_anon_func_9)) + return (function(_arg_0, ...) + local _ok_0 = _arg_0 + _close_2(_) + if _ok_0 then + return ... + else + return error(...) + end + end)(pcall(function() end)) end)) end)) end -- cgit v1.2.3-55-g6feb