Lvalue of setv is checked too early when using or

Fix #1151
This commit is contained in:
Ryan Gonzalez 2016-12-01 01:49:51 -06:00 committed by Tuukka Turto
parent 24ebbc611e
commit 5b879323aa
2 changed files with 49 additions and 5 deletions

View File

@ -1806,16 +1806,17 @@ class HyASTCompiler(object):
ctx=ast.Load(),
lineno=root_line,
col_offset=root_column)
temp_variables = [name, expr_name]
def make_assign(value, node=None):
if node is None:
line, column = root_line, root_column
else:
line, column = node.lineno, node.col_offset
return ast.Assign(targets=[ast.Name(id=var,
ctx=ast.Store(),
lineno=line,
col_offset=column)],
positioned_name = ast.Name(id=var, ctx=ast.Store(),
lineno=line, col_offset=column)
temp_variables.append(positioned_name)
return ast.Assign(targets=[positioned_name],
value=value,
lineno=line,
col_offset=column)
@ -1845,7 +1846,7 @@ class HyASTCompiler(object):
orelse=[]))
current = current[-1].body
ret = sum(root, ret)
ret += Result(expr=expr_name, temp_variables=[expr_name, name])
ret += Result(expr=expr_name, temp_variables=temp_variables)
else:
ret += ast.BoolOp(op=opnode(),
lineno=root_line,

View File

@ -949,6 +949,28 @@
(and 0 (setv a 2))
(assert (= a 1)))
(defn test-and-#1151-do []
(setv a (and 0 (do 2 3)))
(assert (= a 0))
(setv a (and 1 (do 2 3)))
(assert (= a 3)))
(defn test-and-#1151-for []
(setv l [])
(setv x (and 0 (for [n [1 2]] (.append l n))))
(assert (= x 0))
(assert (= l []))
(setv x (and 15 (for [n [1 2]] (.append l n))))
(assert (= l [1 2])))
(defn test-and-#1151-del []
(setv l ["a" "b"])
(setv x (and 0 (del (get l 1))))
(assert (= x 0))
(assert (= l ["a" "b"]))
(setv x (and 15 (del (get l 1))))
(assert (= l ["a"])))
(defn test-or []
"NATIVE: test the or function"
@ -967,6 +989,27 @@
(or 1 (setv a 2))
(assert (= a 1)))
(defn test-or-#1151-do []
(setv a (or 1 (do 2 3)))
(assert (= a 1))
(setv a (or 0 (do 2 3)))
(assert (= a 3)))
(defn test-or-#1151-for []
(setv l [])
(setv x (or 15 (for [n [1 2]] (.append l n))))
(assert (= x 15))
(assert (= l []))
(setv x (or 0 (for [n [1 2]] (.append l n))))
(assert (= l [1 2])))
(defn test-or-#1151-del []
(setv l ["a" "b"])
(setv x (or 15 (del (get l 1))))
(assert (= x 15))
(assert (= l ["a" "b"]))
(setv x (or 0 (del (get l 1))))
(assert (= l ["a"])))
(defn test-xor []
"NATIVE: test the xor macro"