Set the line number correctly for a nested function with an exec or
import *. Mark the offending stmt rather than the function def line.
This commit is contained in:
parent
280e6bd742
commit
2e2cded1b5
|
@ -46,6 +46,7 @@ typedef struct _symtable_entry {
|
||||||
int ste_nested; /* true if scope is nested */
|
int ste_nested; /* true if scope is nested */
|
||||||
int ste_child_free; /* true if a child scope has free variables,
|
int ste_child_free; /* true if a child scope has free variables,
|
||||||
including free refs to globals */
|
including free refs to globals */
|
||||||
|
int ste_opt_lineno; /* lineno of last exec or import * */
|
||||||
struct symtable *ste_table;
|
struct symtable *ste_table;
|
||||||
} PySymtableEntryObject;
|
} PySymtableEntryObject;
|
||||||
|
|
||||||
|
|
|
@ -4241,7 +4241,7 @@ symtable_check_unoptimized(struct compiling *c,
|
||||||
if (c->c_symtable->st_nested_scopes) {
|
if (c->c_symtable->st_nested_scopes) {
|
||||||
PyErr_SetString(PyExc_SyntaxError, buf);
|
PyErr_SetString(PyExc_SyntaxError, buf);
|
||||||
PyErr_SyntaxLocation(c->c_symtable->st_filename,
|
PyErr_SyntaxLocation(c->c_symtable->st_filename,
|
||||||
ste->ste_lineno);
|
ste->ste_opt_lineno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4820,8 +4820,10 @@ symtable_node(struct symtable *st, node *n)
|
||||||
symtable_node(st, CHILD(n, 1));
|
symtable_node(st, CHILD(n, 1));
|
||||||
if (NCH(n) > 2)
|
if (NCH(n) > 2)
|
||||||
symtable_node(st, CHILD(n, 3));
|
symtable_node(st, CHILD(n, 3));
|
||||||
else
|
else {
|
||||||
st->st_cur->ste_optimized |= OPT_BARE_EXEC;
|
st->st_cur->ste_optimized |= OPT_BARE_EXEC;
|
||||||
|
st->st_cur->ste_opt_lineno = n->n_lineno;
|
||||||
|
}
|
||||||
if (NCH(n) > 4)
|
if (NCH(n) > 4)
|
||||||
symtable_node(st, CHILD(n, 5));
|
symtable_node(st, CHILD(n, 5));
|
||||||
break;
|
break;
|
||||||
|
@ -5106,6 +5108,7 @@ symtable_import(struct symtable *st, node *n)
|
||||||
}
|
}
|
||||||
if (TYPE(CHILD(n, 3)) == STAR) {
|
if (TYPE(CHILD(n, 3)) == STAR) {
|
||||||
st->st_cur->ste_optimized |= OPT_IMPORT_STAR;
|
st->st_cur->ste_optimized |= OPT_IMPORT_STAR;
|
||||||
|
st->st_cur->ste_opt_lineno = n->n_lineno;
|
||||||
} else {
|
} else {
|
||||||
for (i = 3; i < NCH(n); i += 2) {
|
for (i = 3; i < NCH(n); i += 2) {
|
||||||
node *c = CHILD(n, i);
|
node *c = CHILD(n, i);
|
||||||
|
|
Loading…
Reference in New Issue