A to-be-closed variable must have a closable value (or be nil)
It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
This commit is contained in:
@@ -266,6 +266,27 @@ do -- errors in __close
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
|
||||
-- errors due to non-closable values
|
||||
local function foo ()
|
||||
local *toclose x = 34
|
||||
end
|
||||
local stat, msg = pcall(foo)
|
||||
assert(not stat and string.find(msg, "variable 'x'"))
|
||||
|
||||
|
||||
-- with other errors, non-closable values are ignored
|
||||
local function foo ()
|
||||
local *toclose x = 34
|
||||
local *toclose y = function () error(32) end
|
||||
end
|
||||
local stat, msg = pcall(foo)
|
||||
assert(not stat and msg == 32)
|
||||
|
||||
end
|
||||
|
||||
|
||||
if rawget(_G, "T") then
|
||||
|
||||
-- memory error inside closing function
|
||||
|
||||
Reference in New Issue
Block a user