commit 5ab6a5756b3c50c99f1388885e9a48a7da8cbe2d
parent 9b4f39ab14fb2e55345c3d23537d129dac23b091
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 23 Aug 2023 13:49:00 -0300
Bug: Wrong line number for function calls
Diffstat:
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lparser.c b/lparser.c
@@ -1022,10 +1022,11 @@ static int explist (LexState *ls, expdesc *v) {
}
-static void funcargs (LexState *ls, expdesc *f, int line) {
+static void funcargs (LexState *ls, expdesc *f) {
FuncState *fs = ls->fs;
expdesc args;
int base, nparams;
+ int line = ls->linenumber;
switch (ls->t.token) {
case '(': { /* funcargs -> '(' [ explist ] ')' */
luaX_next(ls);
@@ -1063,8 +1064,8 @@ static void funcargs (LexState *ls, expdesc *f, int line) {
}
init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
luaK_fixline(fs, line);
- fs->freereg = base+1; /* call remove function and arguments and leaves
- (unless changed) one result */
+ fs->freereg = base+1; /* call removes function and arguments and leaves
+ one result (unless changed later) */
}
@@ -1103,7 +1104,6 @@ static void suffixedexp (LexState *ls, expdesc *v) {
/* suffixedexp ->
primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
FuncState *fs = ls->fs;
- int line = ls->linenumber;
primaryexp(ls, v);
for (;;) {
switch (ls->t.token) {
@@ -1123,12 +1123,12 @@ static void suffixedexp (LexState *ls, expdesc *v) {
luaX_next(ls);
codename(ls, &key);
luaK_self(fs, v, &key);
- funcargs(ls, v, line);
+ funcargs(ls, v);
break;
}
case '(': case TK_STRING: case '{': { /* funcargs */
luaK_exp2nextreg(fs, v);
- funcargs(ls, v, line);
+ funcargs(ls, v);
break;
}
default: return;
diff --git a/testes/errors.lua b/testes/errors.lua
@@ -392,19 +392,19 @@ lineerror("a\n=\n-\n\nprint\n;", 3)
lineerror([[
a
-(
+( -- <<
23)
-]], 1)
+]], 2)
lineerror([[
local a = {x = 13}
a
.
x
-(
+( -- <<
23
)
-]], 2)
+]], 5)
lineerror([[
local a = {x = 13}