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 <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-05-03 22:01:21 +02:00 committed by Nicolas Dandrimont
parent 126e7ac531
commit 9d8accb93a
2 changed files with 10 additions and 6 deletions

View File

@ -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`.

View File

@ -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])))