Skip to content

Commit 6a0dace

Browse files
committed
Bug: 'local function' can assign to '<const>' variables
1 parent 04e1971 commit 6a0dace

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

lparser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,7 @@ static void funcstat (LexState *ls, int line) {
17851785
luaX_next(ls); /* skip FUNCTION */
17861786
ismethod = funcname(ls, &v);
17871787
body(ls, &b, ismethod, line);
1788+
check_readonly(ls, &v);
17881789
luaK_storevar(ls->fs, &v, &b);
17891790
luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
17901791
}

testes/locals.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ do -- constants
187187
checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12")
188188
checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11")
189189
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")
190192

191193
checkro("z", [[
192194
local a, z <const>, b = 10;

0 commit comments

Comments
 (0)