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:
Roberto I
2026-10-15 13:53:40 -03:00
parent b35736b9d7
commit 15b2a78106
4 changed files with 42 additions and 6 deletions
+18 -2
View File
@@ -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