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:
parent
126e7ac531
commit
9d8accb93a
@ -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`.
|
||||
|
@ -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])))
|
||||
|
Loading…
Reference in New Issue
Block a user