Add check for duplicate parameter names.

This commit is contained in:
whitequark 2015-06-15 09:05:24 +03:00
parent d27bb3168d
commit dbfdbc3c22
2 changed files with 11 additions and 1 deletions

View File

@ -71,6 +71,12 @@ class LocalExtractor(algorithm.Visitor):
self.typing_env[name] = types.TVar() self.typing_env[name] = types.TVar()
def visit_arg(self, node): def visit_arg(self, node):
if node.arg in self.params:
diag = diagnostic.Diagnostic("error",
"duplicate parameter '{name}'", {"name": node.arg},
node.loc)
self.engine.process(diag)
return
self._assignable(node.arg) self._assignable(node.arg)
self.params.add(node.arg) self.params.add(node.arg)

View File

@ -20,6 +20,10 @@ def d(x):
# CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and global simultaneously # CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and global simultaneously
global x global x
def d(x): def e(x):
# CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and nonlocal simultaneously # CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and nonlocal simultaneously
nonlocal x nonlocal x
# CHECK-L: ${LINE:+1}: error: duplicate parameter 'x'
def f(x, x):
pass