To-be-closed variables must be closed on initialization
When initializing a to-be-closed variable, check whether it has a '__close' metamethod (or is a false value) and raise an error if if it hasn't. This produces more accurate error messages. (The check before closing still need to be done: in the C API, the value is not constant; and the object may lose its '__close' metamethod during the block.)
This commit is contained in:
6
lvm.c
6
lvm.c
@@ -1739,10 +1739,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_TFORPREP) {
|
||||
if (!ttisnil(s2v(ra + 3))) { /* is 'toclose' not nil? */
|
||||
/* create to-be-closed upvalue for it */
|
||||
halfProtect(luaF_newtbcupval(L, ra + 3));
|
||||
}
|
||||
/* create to-be-closed upvalue (if needed) */
|
||||
halfProtect(luaF_newtbcupval(L, ra + 3));
|
||||
pc += GETARG_Bx(i);
|
||||
i = *(pc++); /* go to next instruction */
|
||||
lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
|
||||
|
||||
Reference in New Issue
Block a user