From 9d8accb93ae3c8d2ef031aa65163bce18e6a16c5 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 3 May 2013 22:01:21 +0200 Subject: [PATCH] compiler: do not optimize Name The optimization is wrong; they can't have side effects, but they can raise errors. Signed-off-by: Julien Danjou --- hy/compiler.py | 8 ++------ tests/native_tests/language.hy | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index b023524..faed069 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -193,17 +193,13 @@ class Result(object): This is useful when we want to use the stored expression in a statement context (for instance in a code branch). - We drop bare names because they can't have any side effect, and they - make the generated code ugly. - If there is no expression context, return an empty result. """ - if self.expr and not isinstance(self.expr, ast.Name): + if self.expr: return Result() + ast.Expr(lineno=self.expr.lineno, col_offset=self.expr.col_offset, value=self.expr) - else: - return Result() + return Result() def rename(self, new_name): """Rename the Result's temporary variables to a `new_name`. diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index ff7df71..20f4d1c 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -640,3 +640,11 @@ (setf f (quote (if true true true))) (assert (= (car f) "if")) (assert (= (cdr f) (quote (true true true))))) + +(defn test-undefined-name [] + "NATIVE: test that undefined names raise errors" + (try + (do + xxx + (assert False)) + (except [NameError])))