aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lcode.c1
-rw-r--r--testes/errors.lua64
2 files changed, 43 insertions, 22 deletions
diff --git a/lcode.c b/lcode.c
index d82f8263..95ef900c 100644
--- a/lcode.c
+++ b/lcode.c
@@ -45,6 +45,7 @@ l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
45 va_list argp; 45 va_list argp;
46 pushvfstring(ls->L, argp, fmt, msg); 46 pushvfstring(ls->L, argp, fmt, msg);
47 ls->t.token = 0; /* remove "near <token>" from final message */ 47 ls->t.token = 0; /* remove "near <token>" from final message */
48 ls->linenumber = ls->lastline; /* back to line of last used token */
48 luaX_syntaxerror(ls, msg); 49 luaX_syntaxerror(ls, msg);
49} 50}
50 51
diff --git a/testes/errors.lua b/testes/errors.lua
index 00a43fc6..c9d85099 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -418,28 +418,28 @@ end
418 418
419-- testing line error 419-- testing line error
420 420
421local function lineerror (s, l) 421local function lineerror (s, l, w)
422 local err,msg = pcall(load(s)) 422 local err,msg = pcall(load(s))
423 local line = tonumber(string.match(msg, ":(%d+):")) 423 local line = tonumber(string.match(msg, ":(%d+):"))
424 assert(line == l or (not line and not l)) 424 assert((line == l or (not line and not l)) and string.find(msg, w))
425end 425end
426 426
427lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) 427lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2, "limit")
428lineerror("\n local a \n for k,v in 3 \n do \n print(k) \n end", 3) 428lineerror("\n local a \n for k,v in 3 \n do \n print(k) \n end", 3, "to call")
429lineerror("\n\n for k,v in \n 3 \n do \n print(k) \n end", 4) 429lineerror("\n\n for k,v in \n 3 \n do \n print(k) \n end", 4, "to call")
430lineerror("function a.x.y ()\na=a+1\nend", 1) 430lineerror("function a.x.y ()\na=a+1\nend", 1, "index")
431 431
432lineerror("a = \na\n+\n{}", 3) 432lineerror("a = \na\n+\n{}", 3, "arithmetic")
433lineerror("a = \n3\n+\n(\n4\n/\nprint)", 6) 433lineerror("a = \n3\n+\n(\n4\n/\nprint)", 6, "arithmetic")
434lineerror("a = \nprint\n+\n(\n4\n/\n7)", 3) 434lineerror("a = \nprint\n+\n(\n4\n/\n7)", 3, "arithmetic")
435 435
436lineerror("a\n=\n-\n\nprint\n;", 3) 436lineerror("a\n=\n-\n\nprint\n;", 3, "arithmetic")
437 437
438lineerror([[ 438lineerror([[
439a 439a
440( -- << 440( -- <<
44123) 44123)
442]], 2) 442]], 2, "call")
443 443
444lineerror([[ 444lineerror([[
445local a = {x = 13} 445local a = {x = 13}
@@ -449,7 +449,7 @@ x
449( -- << 449( -- <<
45023 45023
451) 451)
452]], 5) 452]], 5, "call")
453 453
454lineerror([[ 454lineerror([[
455local a = {x = 13} 455local a = {x = 13}
@@ -459,17 +459,17 @@ x
459( 459(
46023 + a 46023 + a
461) 461)
462]], 6) 462]], 6, "arithmetic")
463 463
464local p = [[ 464local p = [[
465 function g() f() end 465 function g() f() end
466 function f(x) error('a', XX) end 466 function f(x) error('a', XX) end
467g() 467g()
468]] 468]]
469XX=3;lineerror((p), 3) 469XX=3;lineerror((p), 3, "a")
470XX=0;lineerror((p), false) 470XX=0;lineerror((p), false, "a")
471XX=1;lineerror((p), 2) 471XX=1;lineerror((p), 2, "a")
472XX=2;lineerror((p), 1) 472XX=2;lineerror((p), 1, "a")
473_G.XX, _G.g, _G.f = nil 473_G.XX, _G.g, _G.f = nil
474 474
475 475
@@ -477,7 +477,7 @@ lineerror([[
477local b = false 477local b = false
478if not b then 478if not b then
479 error 'test' 479 error 'test'
480end]], 3) 480end]], 3, "test")
481 481
482lineerror([[ 482lineerror([[
483local b = false 483local b = false
@@ -487,7 +487,7 @@ if not b then
487 error 'test' 487 error 'test'
488 end 488 end
489 end 489 end
490end]], 5) 490end]], 5, "test")
491 491
492lineerror([[ 492lineerror([[
493_ENV = 1 493_ENV = 1
@@ -495,7 +495,7 @@ global function foo ()
495 local a = 10 495 local a = 10
496 return a 496 return a
497end 497end
498]], 2) 498]], 2, "index")
499 499
500 500
501-- bug in 5.4.0 501-- bug in 5.4.0
@@ -503,17 +503,37 @@ lineerror([[
503 local a = 0 503 local a = 0
504 local b = 1 504 local b = 1
505 local c = b % a 505 local c = b % a
506]], 3) 506]], 3, "perform")
507 507
508do 508do
509 -- Force a negative estimate for base line. Error in instruction 2 509 -- Force a negative estimate for base line. Error in instruction 2
510 -- (after VARARGPREP, GETGLOBAL), with first absolute line information 510 -- (after VARARGPREP, GETGLOBAL), with first absolute line information
511 -- (forced by too many lines) in instruction 0. 511 -- (forced by too many lines) in instruction 0.
512 local s = string.format("%s return __A.x", string.rep("\n", 300)) 512 local s = string.format("%s return __A.x", string.rep("\n", 300))
513 lineerror(s, 301) 513 lineerror(s, 301, "index")
514end 514end
515 515
516 516
517local function stxlineerror (s, l, w)
518 local err,msg = load(s)
519 local line = tonumber(string.match(msg, ":(%d+):"))
520 assert((line == l or (not line and not l)) and string.find(msg, w, 1, true))
521end
522
523stxlineerror([[
524::L1::
525::L1::
526]], 2, "already defined")
527
528stxlineerror([[
529global none
530local x = b
531]], 2, "not declared")
532
533stxlineerror([[
534local <close> a, b
535]], 1, "multiple")
536
517if not _soft then 537if not _soft then
518 -- several tests that exhaust the Lua stack 538 -- several tests that exhaust the Lua stack
519 collectgarbage() 539 collectgarbage()