aboutsummaryrefslogtreecommitdiff
path: root/testes/locals.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testes/locals.lua50
1 files changed, 25 insertions, 25 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index 814d1b16..c176f506 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -185,9 +185,9 @@ end
185do 185do
186 local a = {} 186 local a = {}
187 do 187 do
188 local *toclose x = setmetatable({"x"}, {__close = function (self) 188 local <toclose> x = setmetatable({"x"}, {__close = function (self)
189 a[#a + 1] = self[1] end}) 189 a[#a + 1] = self[1] end})
190 local *toclose y = func2close(function (self, err) 190 local <toclose> y = func2close(function (self, err)
191 assert(err == nil); a[#a + 1] = "y" 191 assert(err == nil); a[#a + 1] = "y"
192 end) 192 end)
193 a[#a + 1] = "in" 193 a[#a + 1] = "in"
@@ -203,7 +203,7 @@ do
203 203
204 -- closing functions do not corrupt returning values 204 -- closing functions do not corrupt returning values
205 local function foo (x) 205 local function foo (x)
206 local *toclose _ = closescope 206 local <toclose> _ = closescope
207 return x, X, 23 207 return x, X, 23
208 end 208 end
209 209
@@ -212,7 +212,7 @@ do
212 212
213 X = false 213 X = false
214 foo = function (x) 214 foo = function (x)
215 local *toclose _ = closescope 215 local <toclose> _ = closescope
216 local y = 15 216 local y = 15
217 return y 217 return y
218 end 218 end
@@ -221,7 +221,7 @@ do
221 221
222 X = false 222 X = false
223 foo = function () 223 foo = function ()
224 local *toclose x = closescope 224 local <toclose> x = closescope
225 return x 225 return x
226 end 226 end
227 227
@@ -234,13 +234,13 @@ do
234 -- calls cannot be tail in the scope of to-be-closed variables 234 -- calls cannot be tail in the scope of to-be-closed variables
235 local X, Y 235 local X, Y
236 local function foo () 236 local function foo ()
237 local *toclose _ = func2close(function () Y = 10 end) 237 local <toclose> _ = func2close(function () Y = 10 end)
238 assert(X == true and Y == nil) -- 'X' not closed yet 238 assert(X == true and Y == nil) -- 'X' not closed yet
239 return 1,2,3 239 return 1,2,3
240 end 240 end
241 241
242 local function bar () 242 local function bar ()
243 local *toclose _ = func2close(function () X = false end) 243 local <toclose> _ = func2close(function () X = false end)
244 X = true 244 X = true
245 do 245 do
246 return foo() -- not a tail call! 246 return foo() -- not a tail call!
@@ -255,14 +255,14 @@ end
255do -- errors in __close 255do -- errors in __close
256 local log = {} 256 local log = {}
257 local function foo (err) 257 local function foo (err)
258 local *toclose x = 258 local <toclose> x =
259 func2close(function (self, msg) log[#log + 1] = msg; error(1) end) 259 func2close(function (self, msg) log[#log + 1] = msg; error(1) end)
260 local *toclose x1 = 260 local <toclose> x1 =
261 func2close(function (self, msg) log[#log + 1] = msg; end) 261 func2close(function (self, msg) log[#log + 1] = msg; end)
262 local *toclose gc = func2close(function () collectgarbage() end) 262 local <toclose> gc = func2close(function () collectgarbage() end)
263 local *toclose y = 263 local <toclose> y =
264 func2close(function (self, msg) log[#log + 1] = msg; error(2) end) 264 func2close(function (self, msg) log[#log + 1] = msg; error(2) end)
265 local *toclose z = 265 local <toclose> z =
266 func2close(function (self, msg) log[#log + 1] = msg or 10; error(3) end) 266 func2close(function (self, msg) log[#log + 1] = msg or 10; error(3) end)
267 if err then error(4) end 267 if err then error(4) end
268 end 268 end
@@ -283,7 +283,7 @@ do
283 283
284 -- errors due to non-closable values 284 -- errors due to non-closable values
285 local function foo () 285 local function foo ()
286 local *toclose x = 34 286 local <toclose> x = 34
287 end 287 end
288 local stat, msg = pcall(foo) 288 local stat, msg = pcall(foo)
289 assert(not stat and string.find(msg, "variable 'x'")) 289 assert(not stat and string.find(msg, "variable 'x'"))
@@ -291,8 +291,8 @@ do
291 291
292 -- with other errors, non-closable values are ignored 292 -- with other errors, non-closable values are ignored
293 local function foo () 293 local function foo ()
294 local *toclose x = 34 294 local <toclose> x = 34
295 local *toclose y = func2close(function () error(32) end) 295 local <toclose> y = func2close(function () error(32) end)
296 end 296 end
297 local stat, msg = pcall(foo) 297 local stat, msg = pcall(foo)
298 assert(not stat and msg == 32) 298 assert(not stat and msg == 32)
@@ -304,8 +304,8 @@ if rawget(_G, "T") then
304 304
305 -- memory error inside closing function 305 -- memory error inside closing function
306 local function foo () 306 local function foo ()
307 local *toclose y = func2close(function () T.alloccount() end) 307 local <toclose> y = func2close(function () T.alloccount() end)
308 local *toclose x = setmetatable({}, {__close = function () 308 local <toclose> x = setmetatable({}, {__close = function ()
309 T.alloccount(0); local x = {} -- force a memory error 309 T.alloccount(0); local x = {} -- force a memory error
310 end}) 310 end})
311 error("a") -- common error inside the function's body 311 error("a") -- common error inside the function's body
@@ -331,7 +331,7 @@ if rawget(_G, "T") then
331 end 331 end
332 332
333 local function test () 333 local function test ()
334 local *toclose x = enter(0) -- set a memory limit 334 local <toclose> x = enter(0) -- set a memory limit
335 -- creation of previous upvalue will raise a memory error 335 -- creation of previous upvalue will raise a memory error
336 assert(false) -- should not run 336 assert(false) -- should not run
337 end 337 end
@@ -346,14 +346,14 @@ if rawget(_G, "T") then
346 346
347 -- repeat test with extra closing upvalues 347 -- repeat test with extra closing upvalues
348 local function test () 348 local function test ()
349 local *toclose xxx = func2close(function (self, msg) 349 local <toclose> xxx = func2close(function (self, msg)
350 assert(msg == "not enough memory"); 350 assert(msg == "not enough memory");
351 error(1000) -- raise another error 351 error(1000) -- raise another error
352 end) 352 end)
353 local *toclose xx = func2close(function (self, msg) 353 local <toclose> xx = func2close(function (self, msg)
354 assert(msg == "not enough memory"); 354 assert(msg == "not enough memory");
355 end) 355 end)
356 local *toclose x = enter(0) -- set a memory limit 356 local <toclose> x = enter(0) -- set a memory limit
357 -- creation of previous upvalue will raise a memory error 357 -- creation of previous upvalue will raise a memory error
358 os.exit(false) -- should not run 358 os.exit(false) -- should not run
359 end 359 end
@@ -424,9 +424,9 @@ do
424 local x = false 424 local x = false
425 local y = false 425 local y = false
426 local co = coroutine.wrap(function () 426 local co = coroutine.wrap(function ()
427 local *toclose xv = func2close(function () x = true end) 427 local <toclose> xv = func2close(function () x = true end)
428 do 428 do
429 local *toclose yv = func2close(function () y = true end) 429 local <toclose> yv = func2close(function () y = true end)
430 coroutine.yield(100) -- yield doesn't close variable 430 coroutine.yield(100) -- yield doesn't close variable
431 end 431 end
432 coroutine.yield(200) -- yield doesn't close variable 432 coroutine.yield(200) -- yield doesn't close variable
@@ -446,7 +446,7 @@ do
446 -- error in a wrapped coroutine raising errors when closing a variable 446 -- error in a wrapped coroutine raising errors when closing a variable
447 local x = false 447 local x = false
448 local co = coroutine.wrap(function () 448 local co = coroutine.wrap(function ()
449 local *toclose xv = func2close(function () error("XXX") end) 449 local <toclose> xv = func2close(function () error("XXX") end)
450 coroutine.yield(100) 450 coroutine.yield(100)
451 error(200) 451 error(200)
452 end) 452 end)
@@ -461,7 +461,7 @@ end
461-- a suspended coroutine should not close its variables when collected 461-- a suspended coroutine should not close its variables when collected
462local co 462local co
463co = coroutine.wrap(function() 463co = coroutine.wrap(function()
464 local *toclose x = function () os.exit(false) end -- should not run 464 local <toclose> x = function () os.exit(false) end -- should not run
465 co = nil 465 co = nil
466 coroutine.yield() 466 coroutine.yield()
467end) 467end)