summaryrefslogtreecommitdiff
path: root/lfunc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
commit6d04537ea660fd12fc16c328366b701fabaf4919 (patch)
tree41eab6e4d87552e29731db552f7d58d679c56973 /lfunc.c
parent7696c6474fe51ed59fee324e78c1233af74febdd (diff)
downloadlua-github-6d04537ea660fd12fc16c328366b701fabaf4919.tar.gz
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.)
Diffstat (limited to 'lfunc.c')
-rw-r--r--lfunc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lfunc.c b/lfunc.c
index aa6ce58f..11d2850f 100644
--- a/lfunc.c
+++ b/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' */