diff options
Diffstat (limited to 'testes/goto.lua')
-rw-r--r-- | testes/goto.lua | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/testes/goto.lua b/testes/goto.lua index fdfddb85..b41399ff 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -293,8 +293,9 @@ do | |||
293 | assert(not st and string.find(msg, err)) | 293 | assert(not st and string.find(msg, err)) |
294 | end | 294 | end |
295 | 295 | ||
296 | -- globals must be declared after a global declaration | 296 | -- globals must be declared, after a global declaration |
297 | checkerr("global none; X = 1", "variable 'X'") | 297 | checkerr("global none; X = 1", "variable 'X'") |
298 | checkerr("global none; function XX() end", "variable 'XX'") | ||
298 | 299 | ||
299 | -- global variables cannot be to-be-closed | 300 | -- global variables cannot be to-be-closed |
300 | checkerr("global X<close>", "cannot be") | 301 | checkerr("global X<close>", "cannot be") |
@@ -321,6 +322,26 @@ do | |||
321 | -- "global" reserved, cannot be used as a variable | 322 | -- "global" reserved, cannot be used as a variable |
322 | assert(not load("global = 1; return global")) | 323 | assert(not load("global = 1; return global")) |
323 | end | 324 | end |
325 | |||
326 | local foo = 20 | ||
327 | do | ||
328 | global function foo (x) | ||
329 | if x == 0 then return 1 else return 2 * foo(x - 1) end | ||
330 | end | ||
331 | assert(foo == _ENV.foo and foo(4) == 16) | ||
332 | end | ||
333 | assert(_ENV.foo(4) == 16) | ||
334 | assert(foo == 20) -- local one is in context here | ||
335 | |||
336 | do | ||
337 | global foo; | ||
338 | function foo (x) return end -- Ok after declaration | ||
339 | end | ||
340 | |||
341 | checkerr([[ | ||
342 | global foo <const>; | ||
343 | function foo (x) return end -- ERROR: foo is read-only | ||
344 | ]], "assign to const variable 'foo'") | ||
324 | 345 | ||
325 | end | 346 | end |
326 | 347 | ||