Skip to content

Commit

Permalink
fix more cases in try-catch syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed May 17, 2024
1 parent fe317e2 commit 06bf167
Show file tree
Hide file tree
Showing 10 changed files with 556 additions and 137 deletions.
7 changes: 7 additions & 0 deletions spec/inputs/try_catch.yue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ f = ->

success, result = try func 1, 2, 3

tb = {}

try tb.func
try tb.func!
try tb.func()
Expand Down Expand Up @@ -57,4 +59,9 @@ f = ->

try func 1, 2, 3

do
<- x
local tb, a, b, c
f = -> try tb.f a, b, c

nil
2 changes: 2 additions & 0 deletions spec/inputs/upvalue_func.yue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ do
buff_strength = (char, item) ->
item.buffer.strength? char.stats.strength?::ref()

local debug_env_before, debug_env_after

exe_func = (func, env) ->
ok, ... = try
debug_env_before(env)
Expand Down
4 changes: 3 additions & 1 deletion spec/outputs/5.1/attrib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ do
end
})
local _close_2 = assert(getmetatable(_).__close)
return _anon_func_9(_, _close_2, error, pcall(print, "third"))
return _anon_func_9(_, _close_2, error, pcall(function()
return print("third")
end))
end))
end))
end
Expand Down
47 changes: 33 additions & 14 deletions spec/outputs/5.1/try_catch.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
local _anon_func_0 = function(func, print)
print("trying")
return func(1, 2, 3)
local _anon_func_0 = function(tb)
return tb.func
end
local _anon_func_1 = function(tb)
return tb.func
return tb.func()
end
local _anon_func_2 = function(tb)
return tb.func()
Expand All @@ -12,16 +11,16 @@ local _anon_func_3 = function(tb)
return tb.func()
end
local _anon_func_4 = function(tb)
return tb.func()
return tb:func(1, 2, 3)
end
local _anon_func_5 = function(tb)
return tb:func(1, 2, 3)
return tb.func(1)
end
local _anon_func_6 = function(tb)
return tb.func(1)
end
local _anon_func_7 = function(tb)
return tb.func(1)
local _anon_func_7 = function(a, b, c, tb)
return tb.f(a, b, c)
end
local f
f = function()
Expand All @@ -35,22 +34,28 @@ f = function()
end, function(err)
return print(err)
end)
pcall(_anon_func_0, func, print)
pcall(function()
print("trying")
return func(1, 2, 3)
end)
do
local success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(err)
end)
success, result = pcall(func, 1, 2, 3)
success, result = pcall(function()
return func(1, 2, 3)
end)
end
local tb = { }
pcall(_anon_func_0, tb)
pcall(_anon_func_1, tb)
pcall(_anon_func_2, tb)
pcall(_anon_func_3, tb)
pcall(_anon_func_4, tb)
pcall(_anon_func_5, tb)
pcall(_anon_func_6, tb)
pcall(_anon_func_7, tb)
if (xpcall(function()
return func(1)
end, function(err)
Expand All @@ -67,7 +72,9 @@ f = function()
end
do
do
local success, result = pcall(func, "abc", 123)
local success, result = pcall(function()
return func("abc", 123)
end)
if success then
print(result)
end
Expand All @@ -87,8 +94,20 @@ f = function()
end
end
do
pcall(func, 1, 2, 3)
pcall(func, 1, 2, 3)
pcall(function()
return func(1, 2, 3)
end)
pcall(function()
return func(1, 2, 3)
end)
end
do
x(function()
local tb, a, b, c
f = function()
return pcall(_anon_func_7, a, b, c, tb)
end
end)
end
return nil
end
56 changes: 38 additions & 18 deletions spec/outputs/codes_from_doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -608,23 +608,33 @@ end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
end):subscribe(print)
local str = strA .. strB .. strC
func(3000, "192.168.1.1")
xpcall(func, function(err)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
local success, result = xpcall(func, function(err)
end)
local success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return yue.traceback(err)
end, 1, 2, 3)
xpcall(func, function(err)
end)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
success, result = pcall(func, 1, 2, 3)
end)
success, result = pcall(function()
return func(1, 2, 3)
end)
pcall(function()
print("trying")
return func(1, 2, 3)
end)
success, result = xpcall(func, function(err)
success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
end)
if success then
print(result)
end
Expand Down Expand Up @@ -2595,23 +2605,33 @@ end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
end):subscribe(print)
local str = strA .. strB .. strC
func(3000, "192.168.1.1")
xpcall(func, function(err)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
local success, result = xpcall(func, function(err)
end)
local success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return yue.traceback(err)
end, 1, 2, 3)
xpcall(func, function(err)
end)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
success, result = pcall(func, 1, 2, 3)
end)
success, result = pcall(function()
return func(1, 2, 3)
end)
pcall(function()
print("trying")
return func(1, 2, 3)
end)
success, result = xpcall(func, function(err)
success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
end)
if success then
print(result)
end
Expand Down
56 changes: 38 additions & 18 deletions spec/outputs/codes_from_doc_zh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -608,23 +608,33 @@ end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
end):subscribe(print)
local str = strA .. strB .. strC
func(3000, "192.168.1.1")
xpcall(func, function(err)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
local success, result = xpcall(func, function(err)
end)
local success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return yue.traceback(err)
end, 1, 2, 3)
xpcall(func, function(err)
end)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
success, result = pcall(func, 1, 2, 3)
end)
success, result = pcall(function()
return func(1, 2, 3)
end)
pcall(function()
print("尝试中")
return func(1, 2, 3)
end)
success, result = xpcall(func, function(err)
success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
end)
if success then
print(result)
end
Expand Down Expand Up @@ -2589,23 +2599,33 @@ end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
end):subscribe(print)
local str = strA .. strB .. strC
func(3000, "192.168.1.1")
xpcall(func, function(err)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
local success, result = xpcall(func, function(err)
end)
local success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return yue.traceback(err)
end, 1, 2, 3)
xpcall(func, function(err)
end)
xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
success, result = pcall(func, 1, 2, 3)
end)
success, result = pcall(function()
return func(1, 2, 3)
end)
pcall(function()
print("尝试中")
return func(1, 2, 3)
end)
success, result = xpcall(func, function(err)
success, result = xpcall(function()
return func(1, 2, 3)
end, function(err)
return print(yue.traceback(err))
end, 1, 2, 3)
end)
if success then
print(result)
end
Expand Down
Loading

0 comments on commit 06bf167

Please sign in to comment.