Report last error in closing methods

When there are multiple errors around closing methods, report the
last error instead of the original.
This commit is contained in:
Roberto Ierusalimschy
2020-12-22 10:54:25 -03:00
parent f9d29b0c44
commit 0ceada8da9
5 changed files with 35 additions and 101 deletions

10
lfunc.c
View File

@@ -162,14 +162,10 @@ static int callclosemth (lua_State *L, StkId level, int status) {
luaD_seterrorobj(L, status, level); /* set error message */
if (prepclosingmethod(L, uv, s2v(level))) { /* something to call? */
int newstatus = luaD_pcall(L, callclose, NULL, oldtop, 0);
if (newstatus != LUA_OK && status == CLOSEPROTECT) /* first error? */
status = newstatus; /* this will be the new error */
else {
if (newstatus != LUA_OK) /* suppressed error? */
luaE_warnerror(L, "__close metamethod");
/* leave original error (or nil) on top */
if (newstatus != LUA_OK) /* new error? */
status = newstatus; /* this will be the error now */
else /* leave original error (or nil) on top */
L->top = restorestack(L, oldtop);
}
}
/* else no metamethod; ignore this case and keep original error */
}