diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-29 16:02:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-29 16:02:44 -0200 |
commit | 6d04537ea660fd12fc16c328366b701fabaf4919 (patch) | |
tree | 41eab6e4d87552e29731db552f7d58d679c56973 /testes/locals.lua | |
parent | 7696c6474fe51ed59fee324e78c1233af74febdd (diff) | |
download | lua-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.lua | 21 |
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 | |||
266 | end | 266 | end |
267 | 267 | ||
268 | 268 | ||
269 | do | ||
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 | |||
287 | end | ||
288 | |||
289 | |||
269 | if rawget(_G, "T") then | 290 | if rawget(_G, "T") then |
270 | 291 | ||
271 | -- memory error inside closing function | 292 | -- memory error inside closing function |