Allow while
with an empty body
This commit is contained in:
parent
1eccd10d24
commit
b7e5c5f17a
@ -1828,7 +1828,7 @@ class HyASTCompiler(object):
|
||||
return ret
|
||||
|
||||
@builds("while")
|
||||
@checkargs(min=2)
|
||||
@checkargs(min=1)
|
||||
def compile_while_expression(self, expr):
|
||||
expr.pop(0) # "while"
|
||||
cond = expr.pop(0)
|
||||
@ -1867,7 +1867,8 @@ class HyASTCompiler(object):
|
||||
|
||||
ret = cond_compiled + asty.While(
|
||||
expr, test=cond_compiled.force_expr,
|
||||
body=body.stmts, orelse=orel.stmts)
|
||||
body=body.stmts or [asty.Pass(expr)],
|
||||
orelse=orel.stmts)
|
||||
ret.contains_yield = body.contains_yield
|
||||
|
||||
return ret
|
||||
|
@ -97,7 +97,6 @@ def test_ast_invalid_unary_op():
|
||||
def test_ast_bad_while():
|
||||
"Make sure AST can't compile invalid while"
|
||||
cant_compile("(while)")
|
||||
cant_compile("(while (True))")
|
||||
|
||||
|
||||
def test_ast_good_do():
|
||||
|
@ -283,7 +283,21 @@
|
||||
(setv fact (* fact count))
|
||||
(setv count (- count 1)))
|
||||
(assert (= count 0))
|
||||
(assert (= fact 120)))
|
||||
(assert (= fact 120))
|
||||
|
||||
(setv l [])
|
||||
(defn f []
|
||||
(.append l 1)
|
||||
(len l))
|
||||
(while (!= (f) 4))
|
||||
(assert (= l [1 1 1 1]))
|
||||
|
||||
(setv l [])
|
||||
(defn f []
|
||||
(.append l 1)
|
||||
(len l))
|
||||
(while (!= (f) 4) (do))
|
||||
(assert (= l [1 1 1 1])))
|
||||
|
||||
(defn test-while-loop-else []
|
||||
(setv count 5)
|
||||
|
Loading…
Reference in New Issue
Block a user