aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-06 15:54:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-06 15:54:05 -0300
commit4365a45d681b4e71e3c39148489bb8eae538ccf7 (patch)
treeea22f0836f252edd7bc7279772158f2b7e549b1e /testes
parentbe8120906304a8658fab998587b969e0e42f5650 (diff)
downloadlua-4365a45d681b4e71e3c39148489bb8eae538ccf7.tar.gz
lua-4365a45d681b4e71e3c39148489bb8eae538ccf7.tar.bz2
lua-4365a45d681b4e71e3c39148489bb8eae538ccf7.zip
Checks for read-only globals
Diffstat (limited to 'testes')
-rw-r--r--testes/locals.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index eeeb4338..421595bb 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -178,6 +178,8 @@ A = nil
178 178
179 179
180do -- constants 180do -- constants
181 global assert<const>, load, string, X
182 X = 1 -- not a constant
181 local a<const>, b, c<const> = 10, 20, 30 183 local a<const>, b, c<const> = 10, 20, 30
182 b = a + c + b -- 'b' is not constant 184 b = a + c + b -- 'b' is not constant
183 assert(a == 10 and b == 60 and c == 30) 185 assert(a == 10 and b == 60 and c == 30)
@@ -191,6 +193,9 @@ do -- constants
191 checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") 193 checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11")
192 checkro("foo", "local foo <const> = 10; function foo() end") 194 checkro("foo", "local foo <const> = 10; function foo() end")
193 checkro("foo", "local foo <const> = {}; function foo() end") 195 checkro("foo", "local foo <const> = {}; function foo() end")
196 checkro("foo", "global foo <const>; function foo() end")
197 checkro("XX", "global XX <const>; XX = 10")
198 checkro("XX", "local _ENV; global XX <const>; XX = 10")
194 199
195 checkro("z", [[ 200 checkro("z", [[
196 local a, z <const>, b = 10; 201 local a, z <const>, b = 10;
@@ -201,6 +206,11 @@ do -- constants
201 local a, var1 <const> = 10; 206 local a, var1 <const> = 10;
202 function foo() a = 20; z = function () var1 = 12; end end 207 function foo() a = 20; z = function () var1 = 12; end end
203 ]]) 208 ]])
209
210 checkro("var1", [[
211 global a, var1 <const>, z;
212 local function foo() a = 20; z = function () var1 = 12; end end
213 ]])
204end 214end
205 215
206 216