diff options
Diffstat (limited to 'testes/locals.lua')
-rw-r--r-- | testes/locals.lua | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index 73267d02..3b145ca3 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -174,7 +174,7 @@ assert(x==20) | |||
174 | 174 | ||
175 | 175 | ||
176 | do -- constants | 176 | do -- constants |
177 | local <const> a, b, <const> c = 10, 20, 30 | 177 | local a<const>, b, c<const> = 10, 20, 30 |
178 | b = a + c + b -- 'b' is not constant | 178 | b = a + c + b -- 'b' is not constant |
179 | assert(a == 10 and b == 60 and c == 30) | 179 | assert(a == 10 and b == 60 and c == 30) |
180 | local function checkro (name, code) | 180 | local function checkro (name, code) |
@@ -182,17 +182,17 @@ do -- constants | |||
182 | local gab = string.format("attempt to assign to const variable '%s'", name) | 182 | local gab = string.format("attempt to assign to const variable '%s'", name) |
183 | assert(not st and string.find(msg, gab)) | 183 | assert(not st and string.find(msg, gab)) |
184 | end | 184 | end |
185 | checkro("y", "local x, <const> y, z = 10, 20, 30; x = 11; y = 12") | 185 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") |
186 | checkro("x", "local <const> x, y, <const> z = 10, 20, 30; x = 11") | 186 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") |
187 | checkro("z", "local <const> x, y, <const> z = 10, 20, 30; y = 10; z = 11") | 187 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") |
188 | 188 | ||
189 | checkro("z", [[ | 189 | checkro("z", [[ |
190 | local a, <const> z, b = 10; | 190 | local a, z <const>, b = 10; |
191 | function foo() a = 20; z = 32; end | 191 | function foo() a = 20; z = 32; end |
192 | ]]) | 192 | ]]) |
193 | 193 | ||
194 | checkro("var1", [[ | 194 | checkro("var1", [[ |
195 | local a, <const> var1 = 10; | 195 | local a, var1 <const> = 10; |
196 | function foo() a = 20; z = function () var1 = 12; end end | 196 | function foo() a = 20; z = function () var1 = 12; end end |
197 | ]]) | 197 | ]]) |
198 | end | 198 | end |
@@ -215,9 +215,9 @@ end | |||
215 | do | 215 | do |
216 | local a = {} | 216 | local a = {} |
217 | do | 217 | do |
218 | local <toclose> x = setmetatable({"x"}, {__close = function (self) | 218 | local x <close> = setmetatable({"x"}, {__close = function (self) |
219 | a[#a + 1] = self[1] end}) | 219 | a[#a + 1] = self[1] end}) |
220 | local w, <toclose> y, z = func2close(function (self, err) | 220 | local w, y <close>, z = func2close(function (self, err) |
221 | assert(err == nil); a[#a + 1] = "y" | 221 | assert(err == nil); a[#a + 1] = "y" |
222 | end, 10, 20) | 222 | end, 10, 20) |
223 | a[#a + 1] = "in" | 223 | a[#a + 1] = "in" |
@@ -235,7 +235,7 @@ do | |||
235 | 235 | ||
236 | -- closing functions do not corrupt returning values | 236 | -- closing functions do not corrupt returning values |
237 | local function foo (x) | 237 | local function foo (x) |
238 | local <toclose> _ = closescope | 238 | local _ <close> = closescope |
239 | return x, X, 23 | 239 | return x, X, 23 |
240 | end | 240 | end |
241 | 241 | ||
@@ -244,7 +244,7 @@ do | |||
244 | 244 | ||
245 | X = false | 245 | X = false |
246 | foo = function (x) | 246 | foo = function (x) |
247 | local <toclose> _ = closescope | 247 | local _<close> = closescope |
248 | local y = 15 | 248 | local y = 15 |
249 | return y | 249 | return y |
250 | end | 250 | end |
@@ -253,7 +253,7 @@ do | |||
253 | 253 | ||
254 | X = false | 254 | X = false |
255 | foo = function () | 255 | foo = function () |
256 | local <toclose> x = closescope | 256 | local x <close> = closescope |
257 | return x | 257 | return x |
258 | end | 258 | end |
259 | 259 | ||
@@ -266,13 +266,13 @@ do | |||
266 | -- calls cannot be tail in the scope of to-be-closed variables | 266 | -- calls cannot be tail in the scope of to-be-closed variables |
267 | local X, Y | 267 | local X, Y |
268 | local function foo () | 268 | local function foo () |
269 | local <toclose> _ = func2close(function () Y = 10 end) | 269 | local _ <close> = func2close(function () Y = 10 end) |
270 | assert(X == true and Y == nil) -- 'X' not closed yet | 270 | assert(X == true and Y == nil) -- 'X' not closed yet |
271 | return 1,2,3 | 271 | return 1,2,3 |
272 | end | 272 | end |
273 | 273 | ||
274 | local function bar () | 274 | local function bar () |
275 | local <toclose> _ = func2close(function () X = false end) | 275 | local _ <close> = func2close(function () X = false end) |
276 | X = true | 276 | X = true |
277 | do | 277 | do |
278 | return foo() -- not a tail call! | 278 | return foo() -- not a tail call! |
@@ -287,14 +287,14 @@ end | |||
287 | do -- errors in __close | 287 | do -- errors in __close |
288 | local log = {} | 288 | local log = {} |
289 | local function foo (err) | 289 | local function foo (err) |
290 | local <toclose> x = | 290 | local x <close> = |
291 | func2close(function (self, msg) log[#log + 1] = msg; error(1) end) | 291 | func2close(function (self, msg) log[#log + 1] = msg; error(1) end) |
292 | local <toclose> x1 = | 292 | local x1 <close> = |
293 | func2close(function (self, msg) log[#log + 1] = msg; end) | 293 | func2close(function (self, msg) log[#log + 1] = msg; end) |
294 | local <toclose> gc = func2close(function () collectgarbage() end) | 294 | local gc <close> = func2close(function () collectgarbage() end) |
295 | local <toclose> y = | 295 | local y <close> = |
296 | func2close(function (self, msg) log[#log + 1] = msg; error(2) end) | 296 | func2close(function (self, msg) log[#log + 1] = msg; error(2) end) |
297 | local <toclose> z = | 297 | local z <close> = |
298 | func2close(function (self, msg) | 298 | func2close(function (self, msg) |
299 | log[#log + 1] = (msg or 10) + 1; | 299 | log[#log + 1] = (msg or 10) + 1; |
300 | error(3) | 300 | error(3) |
@@ -316,7 +316,7 @@ do -- errors in __close | |||
316 | 316 | ||
317 | -- error in toclose in vararg function | 317 | -- error in toclose in vararg function |
318 | function foo (...) | 318 | function foo (...) |
319 | local <toclose> x123 = 10 | 319 | local x123 <close> = 10 |
320 | end | 320 | end |
321 | 321 | ||
322 | local st, msg = pcall(foo) | 322 | local st, msg = pcall(foo) |
@@ -329,7 +329,7 @@ do | |||
329 | 329 | ||
330 | -- errors due to non-closable values | 330 | -- errors due to non-closable values |
331 | local function foo () | 331 | local function foo () |
332 | local <toclose> x = {} | 332 | local x <close> = {} |
333 | end | 333 | end |
334 | local stat, msg = pcall(foo) | 334 | local stat, msg = pcall(foo) |
335 | assert(not stat and string.find(msg, "variable 'x'")) | 335 | assert(not stat and string.find(msg, "variable 'x'")) |
@@ -337,8 +337,8 @@ do | |||
337 | 337 | ||
338 | -- with other errors, non-closable values are ignored | 338 | -- with other errors, non-closable values are ignored |
339 | local function foo () | 339 | local function foo () |
340 | local <toclose> x = 34 | 340 | local x <close> = 34 |
341 | local <toclose> y = func2close(function () error(32) end) | 341 | local y <close> = func2close(function () error(32) end) |
342 | end | 342 | end |
343 | local stat, msg = pcall(foo) | 343 | local stat, msg = pcall(foo) |
344 | assert(not stat and msg == 32) | 344 | assert(not stat and msg == 32) |
@@ -350,8 +350,8 @@ if rawget(_G, "T") then | |||
350 | 350 | ||
351 | -- memory error inside closing function | 351 | -- memory error inside closing function |
352 | local function foo () | 352 | local function foo () |
353 | local <toclose> y = func2close(function () T.alloccount() end) | 353 | local y <close> = func2close(function () T.alloccount() end) |
354 | local <toclose> x = setmetatable({}, {__close = function () | 354 | local x <close> = setmetatable({}, {__close = function () |
355 | T.alloccount(0); local x = {} -- force a memory error | 355 | T.alloccount(0); local x = {} -- force a memory error |
356 | end}) | 356 | end}) |
357 | error(1000) -- common error inside the function's body | 357 | error(1000) -- common error inside the function's body |
@@ -377,7 +377,7 @@ if rawget(_G, "T") then | |||
377 | end | 377 | end |
378 | 378 | ||
379 | local function test () | 379 | local function test () |
380 | local <toclose> x = enter(0) -- set a memory limit | 380 | local x <close> = enter(0) -- set a memory limit |
381 | -- creation of previous upvalue will raise a memory error | 381 | -- creation of previous upvalue will raise a memory error |
382 | assert(false) -- should not run | 382 | assert(false) -- should not run |
383 | end | 383 | end |
@@ -392,14 +392,14 @@ if rawget(_G, "T") then | |||
392 | 392 | ||
393 | -- repeat test with extra closing upvalues | 393 | -- repeat test with extra closing upvalues |
394 | local function test () | 394 | local function test () |
395 | local <toclose> xxx = func2close(function (self, msg) | 395 | local xxx <close> = func2close(function (self, msg) |
396 | assert(msg == "not enough memory"); | 396 | assert(msg == "not enough memory"); |
397 | error(1000) -- raise another error | 397 | error(1000) -- raise another error |
398 | end) | 398 | end) |
399 | local <toclose> xx = func2close(function (self, msg) | 399 | local xx <close> = func2close(function (self, msg) |
400 | assert(msg == "not enough memory"); | 400 | assert(msg == "not enough memory"); |
401 | end) | 401 | end) |
402 | local <toclose> x = enter(0) -- set a memory limit | 402 | local x <close> = enter(0) -- set a memory limit |
403 | -- creation of previous upvalue will raise a memory error | 403 | -- creation of previous upvalue will raise a memory error |
404 | os.exit(false) -- should not run | 404 | os.exit(false) -- should not run |
405 | end | 405 | end |
@@ -469,9 +469,9 @@ do | |||
469 | local x = false | 469 | local x = false |
470 | local y = false | 470 | local y = false |
471 | local co = coroutine.wrap(function () | 471 | local co = coroutine.wrap(function () |
472 | local <toclose> xv = func2close(function () x = true end) | 472 | local xv <close> = func2close(function () x = true end) |
473 | do | 473 | do |
474 | local <toclose> yv = func2close(function () y = true end) | 474 | local yv <close> = func2close(function () y = true end) |
475 | coroutine.yield(100) -- yield doesn't close variable | 475 | coroutine.yield(100) -- yield doesn't close variable |
476 | end | 476 | end |
477 | coroutine.yield(200) -- yield doesn't close variable | 477 | coroutine.yield(200) -- yield doesn't close variable |
@@ -491,8 +491,8 @@ do | |||
491 | -- error in a wrapped coroutine raising errors when closing a variable | 491 | -- error in a wrapped coroutine raising errors when closing a variable |
492 | local x = 0 | 492 | local x = 0 |
493 | local co = coroutine.wrap(function () | 493 | local co = coroutine.wrap(function () |
494 | local <toclose> xx = func2close(function () x = x + 1; error("YYY") end) | 494 | local xx <close> = func2close(function () x = x + 1; error("YYY") end) |
495 | local <toclose> xv = func2close(function () x = x + 1; error("XXX") end) | 495 | local xv <close> = func2close(function () x = x + 1; error("XXX") end) |
496 | coroutine.yield(100) | 496 | coroutine.yield(100) |
497 | error(200) | 497 | error(200) |
498 | end) | 498 | end) |
@@ -503,8 +503,8 @@ do | |||
503 | local x = 0 | 503 | local x = 0 |
504 | local y = 0 | 504 | local y = 0 |
505 | co = coroutine.wrap(function () | 505 | co = coroutine.wrap(function () |
506 | local <toclose> xx = func2close(function () y = y + 1; error("YYY") end) | 506 | local xx <close> = func2close(function () y = y + 1; error("YYY") end) |
507 | local <toclose> xv = func2close(function () x = x + 1; error("XXX") end) | 507 | local xv <close> = func2close(function () x = x + 1; error("XXX") end) |
508 | coroutine.yield(100) | 508 | coroutine.yield(100) |
509 | return 200 | 509 | return 200 |
510 | end) | 510 | end) |
@@ -519,7 +519,7 @@ end | |||
519 | -- a suspended coroutine should not close its variables when collected | 519 | -- a suspended coroutine should not close its variables when collected |
520 | local co | 520 | local co |
521 | co = coroutine.wrap(function() | 521 | co = coroutine.wrap(function() |
522 | local <toclose> x = function () os.exit(false) end -- should not run | 522 | local x <close> = function () os.exit(false) end -- should not run |
523 | co = nil | 523 | co = nil |
524 | coroutine.yield() | 524 | coroutine.yield() |
525 | end) | 525 | end) |