From be05c444818989463dc307eed283503d391f93eb Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 20 May 2025 17:36:05 -0300 Subject: New way to control preambular declaration Validity of the preambular global declaration in controled together with all declarations, when checking variable names. --- testes/db.lua | 6 +++++- testes/goto.lua | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'testes') diff --git a/testes/db.lua b/testes/db.lua index ae204c41..0f174f17 100644 --- a/testes/db.lua +++ b/testes/db.lua @@ -349,9 +349,11 @@ end, "crl") function f(a,b) - global collectgarbage, assert, g, string + -- declare some globals to check that they don't interfere with 'getlocal' + global collectgarbage collectgarbage() local _, x = debug.getlocal(1, 1) + global assert, g, string local _, y = debug.getlocal(1, 2) assert(x == a and y == b) assert(debug.setlocal(2, 3, "pera") == "AA".."AA") @@ -387,7 +389,9 @@ function g (...) f(AAAA,B) assert(AAAA == "pera" and B == "manga") do + global * local B = 13 + global assert local x,y = debug.getlocal(1,5) assert(x == 'B' and y == 13) end diff --git a/testes/goto.lua b/testes/goto.lua index d7730061..7e40fc4f 100644 --- a/testes/goto.lua +++ b/testes/goto.lua @@ -364,7 +364,23 @@ do print(X) -- Ok to use Y = 1 -- ERROR ]], "assign to const variable 'Y'") - + + checkerr([[ + global *; + Y = X -- Ok to use + global *; + Y = 1 -- ERROR + ]], "assign to const variable 'Y'") + + global * + Y = 10 + assert(_ENV.Y == 10) + global * + local x = Y + global * + Y = x + Y + assert(_ENV.Y == 20) + end print'OK' -- cgit v1.2.3-55-g6feb