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.
This commit is contained in:
Roberto Ierusalimschy
2020-06-01 15:07:58 -03:00
parent 50523b107d
commit 63295f1f7f
3 changed files with 75 additions and 30 deletions

View File

@@ -77,7 +77,7 @@ typedef struct expdesc {
} ind;
struct { /* for local variables */
lu_byte sidx; /* index in the stack */
unsigned short vidx; /* index in 'actvar.arr' */
unsigned short vidx; /* compiler index (in 'actvar.arr') */
} var;
} u;
int t; /* patch list of 'exit when true' */
@@ -125,7 +125,7 @@ typedef struct Labellist {
/* dynamic structures used by the parser */
typedef struct Dyndata {
struct { /* list of active local variables */
struct { /* list of all active local variables */
Vardesc *arr;
int n;
int size;