diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-23 13:49:27 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-23 13:49:27 -0300 |
| commit | 5ab6a5756b3c50c99f1388885e9a48a7da8cbe2d (patch) | |
| tree | 8cee77510f5e919b7c4165370736aac779c8bd77 | |
| parent | 9b4f39ab14fb2e55345c3d23537d129dac23b091 (diff) | |
| download | lua-5ab6a5756b3c50c99f1388885e9a48a7da8cbe2d.tar.gz lua-5ab6a5756b3c50c99f1388885e9a48a7da8cbe2d.tar.bz2 lua-5ab6a5756b3c50c99f1388885e9a48a7da8cbe2d.zip | |
Bug: Wrong line number for function calls
| -rw-r--r-- | lparser.c | 12 | ||||
| -rw-r--r-- | testes/errors.lua | 8 |
2 files changed, 10 insertions, 10 deletions
| @@ -1022,10 +1022,11 @@ static int explist (LexState *ls, expdesc *v) { | |||
| 1022 | } | 1022 | } |
| 1023 | 1023 | ||
| 1024 | 1024 | ||
| 1025 | static void funcargs (LexState *ls, expdesc *f, int line) { | 1025 | static void funcargs (LexState *ls, expdesc *f) { |
| 1026 | FuncState *fs = ls->fs; | 1026 | FuncState *fs = ls->fs; |
| 1027 | expdesc args; | 1027 | expdesc args; |
| 1028 | int base, nparams; | 1028 | int base, nparams; |
| 1029 | int line = ls->linenumber; | ||
| 1029 | switch (ls->t.token) { | 1030 | switch (ls->t.token) { |
| 1030 | case '(': { /* funcargs -> '(' [ explist ] ')' */ | 1031 | case '(': { /* funcargs -> '(' [ explist ] ')' */ |
| 1031 | luaX_next(ls); | 1032 | luaX_next(ls); |
| @@ -1063,8 +1064,8 @@ static void funcargs (LexState *ls, expdesc *f, int line) { | |||
| 1063 | } | 1064 | } |
| 1064 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); | 1065 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); |
| 1065 | luaK_fixline(fs, line); | 1066 | luaK_fixline(fs, line); |
| 1066 | fs->freereg = base+1; /* call remove function and arguments and leaves | 1067 | fs->freereg = base+1; /* call removes function and arguments and leaves |
| 1067 | (unless changed) one result */ | 1068 | one result (unless changed later) */ |
| 1068 | } | 1069 | } |
| 1069 | 1070 | ||
| 1070 | 1071 | ||
| @@ -1103,7 +1104,6 @@ static void suffixedexp (LexState *ls, expdesc *v) { | |||
| 1103 | /* suffixedexp -> | 1104 | /* suffixedexp -> |
| 1104 | primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */ | 1105 | primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */ |
| 1105 | FuncState *fs = ls->fs; | 1106 | FuncState *fs = ls->fs; |
| 1106 | int line = ls->linenumber; | ||
| 1107 | primaryexp(ls, v); | 1107 | primaryexp(ls, v); |
| 1108 | for (;;) { | 1108 | for (;;) { |
| 1109 | switch (ls->t.token) { | 1109 | switch (ls->t.token) { |
| @@ -1123,12 +1123,12 @@ static void suffixedexp (LexState *ls, expdesc *v) { | |||
| 1123 | luaX_next(ls); | 1123 | luaX_next(ls); |
| 1124 | codename(ls, &key); | 1124 | codename(ls, &key); |
| 1125 | luaK_self(fs, v, &key); | 1125 | luaK_self(fs, v, &key); |
| 1126 | funcargs(ls, v, line); | 1126 | funcargs(ls, v); |
| 1127 | break; | 1127 | break; |
| 1128 | } | 1128 | } |
| 1129 | case '(': case TK_STRING: case '{': { /* funcargs */ | 1129 | case '(': case TK_STRING: case '{': { /* funcargs */ |
| 1130 | luaK_exp2nextreg(fs, v); | 1130 | luaK_exp2nextreg(fs, v); |
| 1131 | funcargs(ls, v, line); | 1131 | funcargs(ls, v); |
| 1132 | break; | 1132 | break; |
| 1133 | } | 1133 | } |
| 1134 | default: return; | 1134 | default: return; |
diff --git a/testes/errors.lua b/testes/errors.lua index bf6f389d..b777a329 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -392,19 +392,19 @@ lineerror("a\n=\n-\n\nprint\n;", 3) | |||
| 392 | 392 | ||
| 393 | lineerror([[ | 393 | lineerror([[ |
| 394 | a | 394 | a |
| 395 | ( | 395 | ( -- << |
| 396 | 23) | 396 | 23) |
| 397 | ]], 1) | 397 | ]], 2) |
| 398 | 398 | ||
| 399 | lineerror([[ | 399 | lineerror([[ |
| 400 | local a = {x = 13} | 400 | local a = {x = 13} |
| 401 | a | 401 | a |
| 402 | . | 402 | . |
| 403 | x | 403 | x |
| 404 | ( | 404 | ( -- << |
| 405 | 23 | 405 | 23 |
| 406 | ) | 406 | ) |
| 407 | ]], 2) | 407 | ]], 5) |
| 408 | 408 | ||
| 409 | lineerror([[ | 409 | lineerror([[ |
| 410 | local a = {x = 13} | 410 | local a = {x = 13} |
