aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-06-20 15:36:36 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-06-20 15:36:36 -0300
commit6a0dace25a4b5b77f0fa6911de2ba26ef0fdff2c (patch)
tree89f2089a6e06f9dde9f827af7a59cbefc47081b4
parent04e19712a5d48b84869f9942836ff8314fb0be8e (diff)
downloadlua-6a0dace25a4b5b77f0fa6911de2ba26ef0fdff2c.tar.gz
lua-6a0dace25a4b5b77f0fa6911de2ba26ef0fdff2c.tar.bz2
lua-6a0dace25a4b5b77f0fa6911de2ba26ef0fdff2c.zip
Bug: 'local function' can assign to '<const>' variables
-rw-r--r--lparser.c1
-rw-r--r--testes/locals.lua2
2 files changed, 3 insertions, 0 deletions
diff --git a/lparser.c b/lparser.c
index df9473c2..3abe3d75 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1785,6 +1785,7 @@ static void funcstat (LexState *ls, int line) {
1785 luaX_next(ls); /* skip FUNCTION */ 1785 luaX_next(ls); /* skip FUNCTION */
1786 ismethod = funcname(ls, &v); 1786 ismethod = funcname(ls, &v);
1787 body(ls, &b, ismethod, line); 1787 body(ls, &b, ismethod, line);
1788 check_readonly(ls, &v);
1788 luaK_storevar(ls->fs, &v, &b); 1789 luaK_storevar(ls->fs, &v, &b);
1789 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ 1790 luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
1790} 1791}
diff --git a/testes/locals.lua b/testes/locals.lua
index 6151f64d..62a88df5 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -187,6 +187,8 @@ do -- constants
187 checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") 187 checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12")
188 checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") 188 checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11")
189 checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") 189 checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11")
190 checkro("foo", "local foo <const> = 10; function foo() end")
191 checkro("foo", "local foo <const> = {}; function foo() end")
190 192
191 checkro("z", [[ 193 checkro("z", [[
192 local a, z <const>, b = 10; 194 local a, z <const>, b = 10;