Browse Source

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'.)
pull/22/head
Roberto Ierusalimschy 6 years ago
parent
commit
8004798b03
  1. 10
      lvm.c
  2. 4
      testes/errors.lua
  3. 2
      testes/utf8.lua

10
lvm.c

@ -1556,20 +1556,22 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
L->top = ra + b;
else /* previous instruction set top */
b = cast_int(L->top - ra);
savepc(ci); /* some calls here can raise errors */
if (TESTARG_k(i)) {
int nparams1 = GETARG_C(i);
if (nparams1) /* vararg function? */
delta = ci->u.l.nextraargs + nparams1;
/* close upvalues from current call */
luaF_close(L, base, LUA_OK);
updatestack(ci);
/* close upvalues from current call; the compiler ensures
that there are no to-be-closed variables here */
luaF_close(L, base, NOCLOSINGMETH);
}
if (!ttisfunction(s2v(ra))) { /* not a function? */
luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
b++; /* there is now one extra argument */
}
if (!ttisLclosure(s2v(ra))) { /* C function? */
ProtectNT(luaD_call(L, ra, LUA_MULTRET)); /* call it */
luaD_call(L, ra, LUA_MULTRET); /* call it */
updatetrap(ci);
updatestack(ci); /* stack may have been relocated */
ci->func -= delta;
luaD_poscall(L, ci, cast_int(L->top - ra));

4
testes/errors.lua

@ -99,6 +99,10 @@ assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'"))
checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number")
checkmessage("a=(1)..{}", "a table value")
-- tail calls
checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'")
checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'")
checkmessage("a = #print", "length of a function value")
checkmessage("a = #3", "length of a number value")

2
testes/utf8.lua

@ -66,7 +66,7 @@ local function check (s, t, nonstrict)
assert(utf8.len(s, pi, pi1 - 1, nonstrict) == 1)
assert(utf8.len(s, pi, -1, nonstrict) == l - i + 1)
assert(utf8.len(s, pi1, -1, nonstrict) == l - i)
assert(utf8.len(s, 1, pi, -1, nonstrict) == i)
assert(utf8.len(s, 1, pi, nonstrict) == i)
end
local i = 0

Loading…
Cancel
Save