Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
parameters that contained both anonymous tuples and *arg or **arg. Ex: def f(a, (b, c), *d): pass Fix the symtable_params() to generate names in the right order for co_varnames slot of code object. Consider *arg and **arg before the "complex" names introduced by anonymous tuples.
This commit is contained in:
parent
41eb3c7dc5
commit
a6ebc4841d
@ -4284,7 +4284,7 @@ symtable_default_args(struct symtable *st, node *n)
|
|||||||
static void
|
static void
|
||||||
symtable_params(struct symtable *st, node *n)
|
symtable_params(struct symtable *st, node *n)
|
||||||
{
|
{
|
||||||
int i, complex = 0, ext = 0;
|
int i, complex = -1, ext = 0;
|
||||||
node *c = NULL;
|
node *c = NULL;
|
||||||
|
|
||||||
if (TYPE(n) == parameters) {
|
if (TYPE(n) == parameters) {
|
||||||
@ -4308,17 +4308,9 @@ symtable_params(struct symtable *st, node *n)
|
|||||||
char nbuf[10];
|
char nbuf[10];
|
||||||
sprintf(nbuf, ".%d", i);
|
sprintf(nbuf, ".%d", i);
|
||||||
symtable_add_def(st, nbuf, DEF_PARAM);
|
symtable_add_def(st, nbuf, DEF_PARAM);
|
||||||
complex = 1;
|
complex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (complex) {
|
|
||||||
int j;
|
|
||||||
for (j = 0; j < i; j += 2) {
|
|
||||||
c = CHILD(n, j);
|
|
||||||
if (TYPE(CHILD(c, 0)) == LPAR)
|
|
||||||
symtable_params_fplist(st, CHILD(c, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ext) {
|
if (ext) {
|
||||||
c = CHILD(n, i);
|
c = CHILD(n, i);
|
||||||
if (TYPE(c) == STAR) {
|
if (TYPE(c) == STAR) {
|
||||||
@ -4327,15 +4319,26 @@ symtable_params(struct symtable *st, node *n)
|
|||||||
DEF_PARAM | DEF_STAR);
|
DEF_PARAM | DEF_STAR);
|
||||||
i += 2;
|
i += 2;
|
||||||
if (i >= NCH(n))
|
if (i >= NCH(n))
|
||||||
return;
|
c = NULL;
|
||||||
|
else
|
||||||
c = CHILD(n, i);
|
c = CHILD(n, i);
|
||||||
}
|
}
|
||||||
if (TYPE(c) == DOUBLESTAR) {
|
if (c && TYPE(c) == DOUBLESTAR) {
|
||||||
i++;
|
i++;
|
||||||
symtable_add_def(st, STR(CHILD(n, i)),
|
symtable_add_def(st, STR(CHILD(n, i)),
|
||||||
DEF_PARAM | DEF_DOUBLESTAR);
|
DEF_PARAM | DEF_DOUBLESTAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (complex >= 0) {
|
||||||
|
int j;
|
||||||
|
for (j = 0; j <= complex; j++) {
|
||||||
|
c = CHILD(n, j);
|
||||||
|
if (TYPE(c) == COMMA)
|
||||||
|
c = CHILD(n, ++j);
|
||||||
|
if (TYPE(CHILD(c, 0)) == LPAR)
|
||||||
|
symtable_params_fplist(st, CHILD(c, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user