summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorPeter Schneider-Kamp <nowonder@nowonder.de>2000-07-13 06:15:04 +0000
committerPeter Schneider-Kamp <nowonder@nowonder.de>2000-07-13 06:15:04 +0000
commit609c0f677af9218d29449903aac54c0520925ddb (patch)
tree2d8af6ab2d9df8b830a720f21cf340f0ecb6ca59 /Python
parentcaf5f100c6b9931e8ce47a3979c335582248f79d (diff)
downloadcpython-609c0f677af9218d29449903aac54c0520925ddb.tar.gz
raise error on duplicate function arguments
example: >>> def f(a,a):print a ... SyntaxError: duplicate argument in function definition
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 8cf85a7383..068c10e8ac 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;