mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
raise error on duplicate function arguments
example: >>> def f(a,a):print a ... SyntaxError: duplicate argument in function definition
This commit is contained in:
parent
91826ed2a9
commit
11384c60f6
1 changed files with 10 additions and 1 deletions
|
@ -3092,6 +3092,7 @@ com_arglist(c, n)
|
||||||
node *ch = CHILD(n, i);
|
node *ch = CHILD(n, i);
|
||||||
node *fp;
|
node *fp;
|
||||||
char *name;
|
char *name;
|
||||||
|
PyObject *nameval;
|
||||||
if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR)
|
if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR)
|
||||||
break;
|
break;
|
||||||
REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */
|
REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */
|
||||||
|
@ -3103,7 +3104,15 @@ com_arglist(c, n)
|
||||||
sprintf(nbuf, ".%d", i);
|
sprintf(nbuf, ".%d", i);
|
||||||
complex = 1;
|
complex = 1;
|
||||||
}
|
}
|
||||||
com_newlocal(c, name);
|
nameval = PyString_InternFromString(name);
|
||||||
|
if (nameval == NULL) {
|
||||||
|
c->c_errors++;
|
||||||
|
}
|
||||||
|
if (PyDict_GetItem(c->c_locals, nameval)) {
|
||||||
|
com_error(c, PyExc_SyntaxError,"duplicate argument in function definition");
|
||||||
|
}
|
||||||
|
com_newlocal_o(c, nameval);
|
||||||
|
Py_DECREF(nameval);
|
||||||
c->c_argcount++;
|
c->c_argcount++;
|
||||||
if (++i >= nch)
|
if (++i >= nch)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue