diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-10-07 11:45:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-10-12 12:29:09 -0300 |
commit | c23cc86c542449db47bdb21e9550203309bef045 (patch) | |
tree | 1b7876f7ad26feef4a3ab18f29d3b0b03deabfb2 /testes | |
parent | 171dcd7d745566e69c61845599705707500a104e (diff) | |
download | lua-c23cc86c542449db47bdb21e9550203309bef045.tar.gz lua-c23cc86c542449db47bdb21e9550203309bef045.tar.bz2 lua-c23cc86c542449db47bdb21e9550203309bef045.zip |
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')
-rw-r--r-- | testes/locals.lua | 23 |
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 | |||
246 | 246 | ||
247 | X = false | 247 | X = false |
248 | foo = function (x) | 248 | foo = function (x) |
249 | local _<close> = func2close(function () | ||
250 | -- without errors, enclosing function should be still active when | ||
251 | -- __close is called | ||
252 | assert(debug.getinfo(2).name == "foo") | ||
253 | end) | ||
249 | local _<close> = closescope | 254 | local _<close> = closescope |
250 | local y = 15 | 255 | local y = 15 |
251 | return y | 256 | return y |
@@ -343,6 +348,18 @@ local function endwarn () | |||
343 | end | 348 | end |
344 | 349 | ||
345 | 350 | ||
351 | -- errors inside __close can generate a warning instead of an | ||
352 | -- error. This new 'assert' force them to appear. | ||
353 | local function assert(cond, msg) | ||
354 | if not cond then | ||
355 | local line = debug.getinfo(2).currentline or "?" | ||
356 | msg = string.format("assertion failed! line %d (%s)\n", line, msg or "") | ||
357 | io.stderr:write(msg) | ||
358 | os.exit(1) | ||
359 | end | ||
360 | end | ||
361 | |||
362 | |||
346 | local function checkwarn (msg) | 363 | local function checkwarn (msg) |
347 | if T then | 364 | if T then |
348 | assert(string.find(_WARN, msg)) | 365 | assert(string.find(_WARN, msg)) |
@@ -406,11 +423,15 @@ do print("testing errors in __close") | |||
406 | 423 | ||
407 | local x <close> = | 424 | local x <close> = |
408 | func2close(function (self, msg) | 425 | func2close(function (self, msg) |
426 | -- after error, 'foo' was discarded, so caller now | ||
427 | -- must be 'pcall' | ||
428 | assert(debug.getinfo(2).name == "pcall") | ||
409 | assert(msg == 4) | 429 | assert(msg == 4) |
410 | end) | 430 | end) |
411 | 431 | ||
412 | local x1 <close> = | 432 | local x1 <close> = |
413 | func2close(function (self, msg) | 433 | func2close(function (self, msg) |
434 | assert(debug.getinfo(2).name == "pcall") | ||
414 | checkwarn("@y") | 435 | checkwarn("@y") |
415 | assert(msg == 4) | 436 | assert(msg == 4) |
416 | error("@x1") | 437 | error("@x1") |
@@ -420,6 +441,7 @@ do print("testing errors in __close") | |||
420 | 441 | ||
421 | local y <close> = | 442 | local y <close> = |
422 | func2close(function (self, msg) | 443 | func2close(function (self, msg) |
444 | assert(debug.getinfo(2).name == "pcall") | ||
423 | assert(msg == 4) -- error in body | 445 | assert(msg == 4) -- error in body |
424 | checkwarn("@z") | 446 | checkwarn("@z") |
425 | error("@y") | 447 | error("@y") |
@@ -428,6 +450,7 @@ do print("testing errors in __close") | |||
428 | local first = true | 450 | local first = true |
429 | local z <close> = | 451 | local z <close> = |
430 | func2close(function (self, msg) | 452 | func2close(function (self, msg) |
453 | assert(debug.getinfo(2).name == "pcall") | ||
431 | -- 'z' close is called once | 454 | -- 'z' close is called once |
432 | assert(first and msg == 4) | 455 | assert(first and msg == 4) |
433 | first = false | 456 | first = false |