summaryrefslogtreecommitdiff
path: root/testes/locals.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-07 11:45:23 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-12 12:29:09 -0300
commitc23cc86c542449db47bdb21e9550203309bef045 (patch)
tree1b7876f7ad26feef4a3ab18f29d3b0b03deabfb2 /testes/locals.lua
parent171dcd7d745566e69c61845599705707500a104e (diff)
downloadlua-github-c23cc86c542449db47bdb21e9550203309bef045.tar.gz
Details
- After converting a generic GCObject to a specific type ('gco2*'), avoid using the original GCObject (to reduce aliasing). - Small corrections in comments in 'lopcodes.h' - Added tests about who calls __close metamethods
Diffstat (limited to 'testes/locals.lua')
-rw-r--r--testes/locals.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index f5e96244..df44b86f 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -246,6 +246,11 @@ do
X = false
foo = function (x)
+ local _<close> = func2close(function ()
+ -- without errors, enclosing function should be still active when
+ -- __close is called
+ assert(debug.getinfo(2).name == "foo")
+ end)
local _<close> = closescope
local y = 15
return y
@@ -343,6 +348,18 @@ local function endwarn ()
end
+-- errors inside __close can generate a warning instead of an
+-- error. This new 'assert' force them to appear.
+local function assert(cond, msg)
+ if not cond then
+ local line = debug.getinfo(2).currentline or "?"
+ msg = string.format("assertion failed! line %d (%s)\n", line, msg or "")
+ io.stderr:write(msg)
+ os.exit(1)
+ end
+end
+
+
local function checkwarn (msg)
if T then
assert(string.find(_WARN, msg))
@@ -406,11 +423,15 @@ do print("testing errors in __close")
local x <close> =
func2close(function (self, msg)
+ -- after error, 'foo' was discarded, so caller now
+ -- must be 'pcall'
+ assert(debug.getinfo(2).name == "pcall")
assert(msg == 4)
end)
local x1 <close> =
func2close(function (self, msg)
+ assert(debug.getinfo(2).name == "pcall")
checkwarn("@y")
assert(msg == 4)
error("@x1")
@@ -420,6 +441,7 @@ do print("testing errors in __close")
local y <close> =
func2close(function (self, msg)
+ assert(debug.getinfo(2).name == "pcall")
assert(msg == 4) -- error in body
checkwarn("@z")
error("@y")
@@ -428,6 +450,7 @@ do print("testing errors in __close")
local first = true
local z <close> =
func2close(function (self, msg)
+ assert(debug.getinfo(2).name == "pcall")
-- 'z' close is called once
assert(first and msg == 4)
first = false