From dbfdbc3c22fffced22b20d5057f481cf23f9fabb Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 15 Jun 2015 09:05:24 +0300 Subject: [PATCH] Add check for duplicate parameter names. --- artiq/py2llvm/typing.py | 6 ++++++ .../typing/{error_nonlocal_global.py => error_locals.py} | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) rename lit-test/py2llvm/typing/{error_nonlocal_global.py => error_locals.py} (89%) diff --git a/artiq/py2llvm/typing.py b/artiq/py2llvm/typing.py index 5d2b140a9..29981389a 100644 --- a/artiq/py2llvm/typing.py +++ b/artiq/py2llvm/typing.py @@ -71,6 +71,12 @@ class LocalExtractor(algorithm.Visitor): self.typing_env[name] = types.TVar() 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.params.add(node.arg) diff --git a/lit-test/py2llvm/typing/error_nonlocal_global.py b/lit-test/py2llvm/typing/error_locals.py similarity index 89% rename from lit-test/py2llvm/typing/error_nonlocal_global.py rename to lit-test/py2llvm/typing/error_locals.py index 1242f56db..7d07d699b 100644 --- a/lit-test/py2llvm/typing/error_nonlocal_global.py +++ b/lit-test/py2llvm/typing/error_locals.py @@ -20,6 +20,10 @@ def d(x): # CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and global simultaneously global x -def d(x): +def e(x): # CHECK-L: ${LINE:+1}: error: name 'x' cannot be a parameter and nonlocal simultaneously nonlocal x + +# CHECK-L: ${LINE:+1}: error: duplicate parameter 'x' +def f(x, x): + pass