diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-04 16:31:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-04 16:31:24 -0300 |
commit | 8004798b0374744208b102bb4cbcf12f904ea120 (patch) | |
tree | 0809ccedaa52f187505121c3b85029d7496465b9 | |
parent | 5ca1075b714e825006e8ba4f8e7ea5544879bb41 (diff) | |
download | lua-8004798b0374744208b102bb4cbcf12f904ea120.tar.gz lua-8004798b0374744208b102bb4cbcf12f904ea120.tar.bz2 lua-8004798b0374744208b102bb4cbcf12f904ea120.zip |
Fixed wrong error message in 'return math.seed(0)'
Bug introduced in commit 28d829c8: OP_TAILCALL might raise an
error without saving 'pc'. (This commit also fixes a detail in
'testes/uf8.lua'.)
-rw-r--r-- | lvm.c | 10 | ||||
-rw-r--r-- | testes/errors.lua | 4 | ||||
-rw-r--r-- | testes/utf8.lua | 2 |
3 files changed, 11 insertions, 5 deletions
@@ -1556,20 +1556,22 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1556 | L->top = ra + b; | 1556 | L->top = ra + b; |
1557 | else /* previous instruction set top */ | 1557 | else /* previous instruction set top */ |
1558 | b = cast_int(L->top - ra); | 1558 | b = cast_int(L->top - ra); |
1559 | savepc(ci); /* some calls here can raise errors */ | ||
1559 | if (TESTARG_k(i)) { | 1560 | if (TESTARG_k(i)) { |
1560 | int nparams1 = GETARG_C(i); | 1561 | int nparams1 = GETARG_C(i); |
1561 | if (nparams1) /* vararg function? */ | 1562 | if (nparams1) /* vararg function? */ |
1562 | delta = ci->u.l.nextraargs + nparams1; | 1563 | delta = ci->u.l.nextraargs + nparams1; |
1563 | /* close upvalues from current call */ | 1564 | /* close upvalues from current call; the compiler ensures |
1564 | luaF_close(L, base, LUA_OK); | 1565 | that there are no to-be-closed variables here */ |
1565 | updatestack(ci); | 1566 | luaF_close(L, base, NOCLOSINGMETH); |
1566 | } | 1567 | } |
1567 | if (!ttisfunction(s2v(ra))) { /* not a function? */ | 1568 | if (!ttisfunction(s2v(ra))) { /* not a function? */ |
1568 | luaD_tryfuncTM(L, ra); /* try '__call' metamethod */ | 1569 | luaD_tryfuncTM(L, ra); /* try '__call' metamethod */ |
1569 | b++; /* there is now one extra argument */ | 1570 | b++; /* there is now one extra argument */ |
1570 | } | 1571 | } |
1571 | if (!ttisLclosure(s2v(ra))) { /* C function? */ | 1572 | if (!ttisLclosure(s2v(ra))) { /* C function? */ |
1572 | ProtectNT(luaD_call(L, ra, LUA_MULTRET)); /* call it */ | 1573 | luaD_call(L, ra, LUA_MULTRET); /* call it */ |
1574 | updatetrap(ci); | ||
1573 | updatestack(ci); /* stack may have been relocated */ | 1575 | updatestack(ci); /* stack may have been relocated */ |
1574 | ci->func -= delta; | 1576 | ci->func -= delta; |
1575 | luaD_poscall(L, ci, cast_int(L->top - ra)); | 1577 | luaD_poscall(L, ci, cast_int(L->top - ra)); |
diff --git a/testes/errors.lua b/testes/errors.lua index 74975e31..0b12410e 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -99,6 +99,10 @@ assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'")) | |||
99 | checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") | 99 | checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") |
100 | checkmessage("a=(1)..{}", "a table value") | 100 | checkmessage("a=(1)..{}", "a table value") |
101 | 101 | ||
102 | -- tail calls | ||
103 | checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'") | ||
104 | checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'") | ||
105 | |||
102 | checkmessage("a = #print", "length of a function value") | 106 | checkmessage("a = #print", "length of a function value") |
103 | checkmessage("a = #3", "length of a number value") | 107 | checkmessage("a = #3", "length of a number value") |
104 | 108 | ||
diff --git a/testes/utf8.lua b/testes/utf8.lua index b3b7687f..acbb181d 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
@@ -66,7 +66,7 @@ local function check (s, t, nonstrict) | |||
66 | assert(utf8.len(s, pi, pi1 - 1, nonstrict) == 1) | 66 | assert(utf8.len(s, pi, pi1 - 1, nonstrict) == 1) |
67 | assert(utf8.len(s, pi, -1, nonstrict) == l - i + 1) | 67 | assert(utf8.len(s, pi, -1, nonstrict) == l - i + 1) |
68 | assert(utf8.len(s, pi1, -1, nonstrict) == l - i) | 68 | assert(utf8.len(s, pi1, -1, nonstrict) == l - i) |
69 | assert(utf8.len(s, 1, pi, -1, nonstrict) == i) | 69 | assert(utf8.len(s, 1, pi, nonstrict) == i) |
70 | end | 70 | end |
71 | 71 | ||
72 | local i = 0 | 72 | local i = 0 |