From c23cc86c542449db47bdb21e9550203309bef045 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 7 Oct 2020 11:45:23 -0300 Subject: 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 --- testes/locals.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'testes') 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 _ = func2close(function () + -- without errors, enclosing function should be still active when + -- __close is called + assert(debug.getinfo(2).name == "foo") + end) local _ = 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 = 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 = 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 = 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 = func2close(function (self, msg) + assert(debug.getinfo(2).name == "pcall") -- 'z' close is called once assert(first and msg == 4) first = false -- cgit v1.2.3-55-g6feb