mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Fix for SF bug [ 784075 ] Fatal Python error: unknown scope
Make sure the inner function is not compiled when there is a syntax error in the default arguments.
This commit is contained in:
parent
ead21f596c
commit
376e63d5cd
1 changed files with 12 additions and 4 deletions
|
@ -3666,10 +3666,16 @@ com_continue_stmt(struct compiling *c, node *n)
|
||||||
XXX if we could pop the exception still on the stack */
|
XXX if we could pop the exception still on the stack */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the number of default values in the argument list.
|
||||||
|
|
||||||
|
If a non-default argument follows a default argument, set an
|
||||||
|
exception and return -1.
|
||||||
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
com_argdefs(struct compiling *c, node *n)
|
com_argdefs(struct compiling *c, node *n)
|
||||||
{
|
{
|
||||||
int i, nch, nargs, ndefs;
|
int i, nch, ndefs;
|
||||||
if (TYPE(n) == lambdef) {
|
if (TYPE(n) == lambdef) {
|
||||||
/* lambdef: 'lambda' [varargslist] ':' test */
|
/* lambdef: 'lambda' [varargslist] ':' test */
|
||||||
n = CHILD(n, 1);
|
n = CHILD(n, 1);
|
||||||
|
@ -3686,14 +3692,12 @@ com_argdefs(struct compiling *c, node *n)
|
||||||
(fpdef ['=' test] ',')* '*' ....... |
|
(fpdef ['=' test] ',')* '*' ....... |
|
||||||
fpdef ['=' test] (',' fpdef ['=' test])* [','] */
|
fpdef ['=' test] (',' fpdef ['=' test])* [','] */
|
||||||
nch = NCH(n);
|
nch = NCH(n);
|
||||||
nargs = 0;
|
|
||||||
ndefs = 0;
|
ndefs = 0;
|
||||||
for (i = 0; i < nch; i++) {
|
for (i = 0; i < nch; i++) {
|
||||||
int t;
|
int t;
|
||||||
if (TYPE(CHILD(n, i)) == STAR ||
|
if (TYPE(CHILD(n, i)) == STAR ||
|
||||||
TYPE(CHILD(n, i)) == DOUBLESTAR)
|
TYPE(CHILD(n, i)) == DOUBLESTAR)
|
||||||
break;
|
break;
|
||||||
nargs++;
|
|
||||||
i++;
|
i++;
|
||||||
if (i >= nch)
|
if (i >= nch)
|
||||||
t = RPAR; /* Anything except EQUAL or COMMA */
|
t = RPAR; /* Anything except EQUAL or COMMA */
|
||||||
|
@ -3710,9 +3714,11 @@ com_argdefs(struct compiling *c, node *n)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Treat "(a=1, b)" as an error */
|
/* Treat "(a=1, b)" as an error */
|
||||||
if (ndefs)
|
if (ndefs) {
|
||||||
com_error(c, PyExc_SyntaxError,
|
com_error(c, PyExc_SyntaxError,
|
||||||
"non-default argument follows default argument");
|
"non-default argument follows default argument");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (t != COMMA)
|
if (t != COMMA)
|
||||||
break;
|
break;
|
||||||
|
@ -3727,6 +3733,8 @@ com_funcdef(struct compiling *c, node *n)
|
||||||
int ndefs;
|
int ndefs;
|
||||||
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
|
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
|
||||||
ndefs = com_argdefs(c, n);
|
ndefs = com_argdefs(c, n);
|
||||||
|
if (ndefs < 0)
|
||||||
|
return;
|
||||||
symtable_enter_scope(c->c_symtable, STR(CHILD(n, 1)), TYPE(n),
|
symtable_enter_scope(c->c_symtable, STR(CHILD(n, 1)), TYPE(n),
|
||||||
n->n_lineno);
|
n->n_lineno);
|
||||||
co = (PyObject *)icompile(n, c);
|
co = (PyObject *)icompile(n, c);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue