From b0c6b70971d35c88b6c7f8b3e04488124ef4eab1 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 17 Nov 2015 01:17:25 +0300 Subject: [PATCH] transforms.asttyped_rewriter: fix class redefinition diagnostic. --- artiq/compiler/transforms/asttyped_rewriter.py | 2 +- lit-test/test/inferencer/error_class.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index 20aecdb62..084b8a7ca 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -263,7 +263,7 @@ class ASTTypedRewriter(algorithm.Transformer): if node.name in self.env_stack[-1]: diag = diagnostic.Diagnostic("fatal", - "variable '{name}' is already defined", {"name":name}, loc) + "variable '{name}' is already defined", {"name":node.name}, node.name_loc) self.engine.process(diag) extractor = LocalExtractor(env_stack=self.env_stack, engine=self.engine) diff --git a/lit-test/test/inferencer/error_class.py b/lit-test/test/inferencer/error_class.py index 0cc075b05..dbb399494 100644 --- a/lit-test/test/inferencer/error_class.py +++ b/lit-test/test/inferencer/error_class.py @@ -8,3 +8,9 @@ class a(1): class b: # CHECK-L: ${LINE:+1}: fatal: class body must contain only assignments and function definitions x += 1 + +class c: + pass +# CHECK-L: ${LINE:+1}: fatal: variable 'c' is already defined +class c: + pass