diff options
author | Peter Schneider-Kamp <nowonder@nowonder.de> | 2000-07-13 06:15:04 (GMT) |
---|---|---|
committer | Peter Schneider-Kamp <nowonder@nowonder.de> | 2000-07-13 06:15:04 (GMT) |
commit | 11384c60f625f2f050cd51baa1333115fa95ab6c (patch) | |
tree | 8b24fb66644906200a2afc34cc76e8baf1930efc /Python/compile.c | |
parent | 91826ed2a9e6f2b6f6b01f77b6d63532bf66d6f7 (diff) | |
download | cpython-11384c60f625f2f050cd51baa1333115fa95ab6c.zip cpython-11384c60f625f2f050cd51baa1333115fa95ab6c.tar.gz cpython-11384c60f625f2f050cd51baa1333115fa95ab6c.tar.bz2 |
raise error on duplicate function arguments
example:
>>> def f(a,a):print a
...
SyntaxError: duplicate argument in function definition
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index 8cf85a7..068c10e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3092,6 +3092,7 @@ com_arglist(c, n) node *ch = CHILD(n, i); node *fp; char *name; + PyObject *nameval; if (TYPE(ch) == STAR || TYPE(ch) == DOUBLESTAR) break; REQ(ch, fpdef); /* fpdef: NAME | '(' fplist ')' */ @@ -3103,7 +3104,15 @@ com_arglist(c, n) sprintf(nbuf, ".%d", i); 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++; if (++i >= nch) break; |