mirror of
https://github.com/lua/lua
synced 2026-09-27 00:28:25 +03:00
A to-be-closed variable must have a closable value (or be nil)
It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
This commit is contained in:
parent
7696c6474f
commit
6d04537ea6
9 changed files with 83 additions and 39 deletions
6
lfunc.c
6
lfunc.c
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "lua.h"
|
||||
|
||||
#include "ldebug.h"
|
||||
#include "ldo.h"
|
||||
#include "lfunc.h"
|
||||
#include "lgc.h"
|
||||
|
|
@ -140,6 +141,11 @@ static int closeupval (lua_State *L, TValue *uv, StkId level, int status) {
|
|||
if (likely(status == LUA_OK)) {
|
||||
if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */
|
||||
callclose(L, NULL); /* call closing method */
|
||||
else if (!ttisnil(uv)) { /* non-closable non-nil value? */
|
||||
const char *vname = luaG_findlocal(L, L->ci, level - L->ci->func, NULL);
|
||||
if (vname == NULL) vname = "?";
|
||||
luaG_runerror(L, "attempt to close non-closable variable '%s'", vname);
|
||||
}
|
||||
}
|
||||
else { /* there was an error */
|
||||
/* save error message and set stack top to 'level + 1' */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue