mirror of
https://github.com/lua/lua.git
synced 2026-10-26 18:45:25 +00:00
Bug: Calling coroutine.close while closing after error
A call to 'coroutine.close()' while closing the coroutine returns like 'resume', with no errors, even if the coroutine previously had stopped due to an error.
This commit is contained in:
+18
-2
@@ -156,8 +156,6 @@ do
|
||||
st, msg = coroutine.close(co)
|
||||
assert(st and msg == nil)
|
||||
|
||||
local main = coroutine.running()
|
||||
|
||||
-- cannot close 'main'
|
||||
local st, msg = pcall(coroutine.close, main);
|
||||
assert(not st and string.find(msg, "main"))
|
||||
@@ -184,6 +182,24 @@ do
|
||||
assert(st and msg == nil)
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
-- again close a coroutine while closing it, but with the
|
||||
-- coroutine in error mode.
|
||||
|
||||
-- after the error, the function created by 'wrap' will close the
|
||||
-- coroutine. The close inside 'a' overrides the original close
|
||||
-- and finishes the coroutine with no errors.
|
||||
local co = coroutine.wrap(function()
|
||||
local a <close> = func2close(function()
|
||||
coroutine.close()
|
||||
end)
|
||||
error("y")
|
||||
end)
|
||||
co() -- no errors
|
||||
end
|
||||
|
||||
|
||||
-- to-be-closed variables in coroutines
|
||||
local X
|
||||
|
||||
|
||||
Reference in New Issue
Block a user