New way to control preambular declaration

Validity of the preambular global declaration in controled together
with all declarations, when checking variable names.
This commit is contained in:
Roberto Ierusalimschy
2025-05-20 17:36:05 -03:00
parent 6d53701c7a
commit be05c44481
4 changed files with 45 additions and 15 deletions

View File

@@ -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<const> assert
local x,y = debug.getlocal(1,5)
assert(x == 'B' and y == 13)
end

View File

@@ -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<const> *;
Y = 1 -- ERROR
]], "assign to const variable 'Y'")
global *
Y = 10
assert(_ENV.Y == 10)
global<const> *
local x = Y
global *
Y = x + Y
assert(_ENV.Y == 20)
end
print'OK'