@@ -3666,10 +3666,16 @@ com_continue_stmt(struct compiling *c, node *n)
36663666 XXX if we could pop the exception still on the stack */
36673667}
36683668
3669+ /* Return the number of default values in the argument list.
3670+
3671+ If a non-default argument follows a default argument, set an
3672+ exception and return -1.
3673+ */
3674+
36693675static int
36703676com_argdefs (struct compiling * c , node * n )
36713677{
3672- int i , nch , nargs , ndefs ;
3678+ int i , nch , ndefs ;
36733679 if (TYPE (n ) == lambdef ) {
36743680 /* lambdef: 'lambda' [varargslist] ':' test */
36753681 n = CHILD (n , 1 );
@@ -3686,14 +3692,12 @@ com_argdefs(struct compiling *c, node *n)
36863692 (fpdef ['=' test] ',')* '*' ....... |
36873693 fpdef ['=' test] (',' fpdef ['=' test])* [','] */
36883694 nch = NCH (n );
3689- nargs = 0 ;
36903695 ndefs = 0 ;
36913696 for (i = 0 ; i < nch ; i ++ ) {
36923697 int t ;
36933698 if (TYPE (CHILD (n , i )) == STAR ||
36943699 TYPE (CHILD (n , i )) == DOUBLESTAR )
36953700 break ;
3696- nargs ++ ;
36973701 i ++ ;
36983702 if (i >= nch )
36993703 t = RPAR ; /* Anything except EQUAL or COMMA */
@@ -3710,9 +3714,11 @@ com_argdefs(struct compiling *c, node *n)
37103714 }
37113715 else {
37123716 /* Treat "(a=1, b)" as an error */
3713- if (ndefs )
3717+ if (ndefs ) {
37143718 com_error (c , PyExc_SyntaxError ,
37153719 "non-default argument follows default argument" );
3720+ return -1 ;
3721+ }
37163722 }
37173723 if (t != COMMA )
37183724 break ;
@@ -3727,6 +3733,8 @@ com_funcdef(struct compiling *c, node *n)
37273733 int ndefs ;
37283734 REQ (n , funcdef ); /* funcdef: 'def' NAME parameters ':' suite */
37293735 ndefs = com_argdefs (c , n );
3736+ if (ndefs < 0 )
3737+ return ;
37303738 symtable_enter_scope (c -> c_symtable , STR (CHILD (n , 1 )), TYPE (n ),
37313739 n -> n_lineno );
37323740 co = (PyObject * )icompile (n , c );
0 commit comments