aboutsummaryrefslogtreecommitdiff
path: root/testes/locals.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
commit6d04537ea660fd12fc16c328366b701fabaf4919 (patch)
tree41eab6e4d87552e29731db552f7d58d679c56973 /testes/locals.lua
parent7696c6474fe51ed59fee324e78c1233af74febdd (diff)
downloadlua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.gz
lua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.bz2
lua-6d04537ea660fd12fc16c328366b701fabaf4919.zip
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.)
Diffstat (limited to 'testes/locals.lua')
-rw-r--r--testes/locals.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index 90a8b845..24681dd9 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -266,6 +266,27 @@ do -- errors in __close
266end 266end
267 267
268 268
269do
270
271 -- errors due to non-closable values
272 local function foo ()
273 local *toclose x = 34
274 end
275 local stat, msg = pcall(foo)
276 assert(not stat and string.find(msg, "variable 'x'"))
277
278
279 -- with other errors, non-closable values are ignored
280 local function foo ()
281 local *toclose x = 34
282 local *toclose y = function () error(32) end
283 end
284 local stat, msg = pcall(foo)
285 assert(not stat and msg == 32)
286
287end
288
289
269if rawget(_G, "T") then 290if rawget(_G, "T") then
270 291
271 -- memory error inside closing function 292 -- memory error inside closing function