Fixed two bugs in to-be-closed variables x constants · lua/lua@63295f1 · GitHub
Skip to content

Commit 63295f1

Browse files
committed
Fixed two bugs in to-be-closed variables x constants
The parser were mixing compiler indices of variables with stack indices, so that when a to-be-closed variable was used inside the scope of compile-time constants (which may be optimized away), it might be closed in the wrong place. (See new tests for examples.) Besides fixing the bugs, this commit also changed comments and variable names to avoid that kind of confusion and added tests.
1 parent 50523b1 commit 63295f1

3 files changed

Lines changed: 75 additions & 30 deletions

File tree

‎lparser.c‎

Lines changed: 36 additions & 28 deletions

‎lparser.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef struct expdesc {
7777
} ind;
7878
struct { /* for local variables */
7979
lu_byte sidx; /* index in the stack */
80-
unsigned short vidx; /* index in 'actvar.arr' */
80+
unsigned short vidx; /* compiler index (in 'actvar.arr') */
8181
} var;
8282
} u;
8383
int t; /* patch list of 'exit when true' */
@@ -125,7 +125,7 @@ typedef struct Labellist {
125125

126126
/* dynamic structures used by the parser */
127127
typedef struct Dyndata {
128-
struct { /* list of active local variables */
128+
struct { /* list of all active local variables */
129129
Vardesc *arr;
130130
int n;
131131
int size;

‎testes/locals.lua‎

Lines changed: 37 additions & 0 deletions

0 commit comments

Comments
 (0)