]> granicus.if.org Git - python/commitdiff
raise error on duplicate function arguments
authorPeter Schneider-Kamp <nowonder@nowonder.de>
Thu, 13 Jul 2000 06:15:04 +0000 (06:15 +0000)
committerPeter Schneider-Kamp <nowonder@nowonder.de>
Thu, 13 Jul 2000 06:15:04 +0000 (06:15 +0000)
example:

>>> def f(a,a):print a
...
SyntaxError: duplicate argument in function definition

Python/compile.c

index 8cf85a738315ed216e0b4656ad37a1107dbf1e4e..068c10e8acb988f5126f4ce2ed2b59edb273ec25 100644 (file)
@@ -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;