diff --git a/hy/compiler.py b/hy/compiler.py index 9e98af5..5514263 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -72,10 +72,21 @@ class HyASTCompiler(object): ret.append(ast.Return(value=el, lineno=el.lineno, col_offset=el.col_offset)) - ret += [ast.Expr(value=el, - lineno=el.lineno, - col_offset=el.col_offset) - if not isinstance(el, ast.stmt) else el for el in tree] # NOQA + + for el in tree: + if type(el) == list: + blob = self._mangle_branch(el) + blob.reverse() + ret += blob + continue + + if isinstance(el, ast.stmt): + ret.append(el) + continue + + ret.append(ast.Expr(value=el, + lineno=el.lineno, + col_offset=el.col_offset)) ret.reverse() return ret diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index ffc6109..3e92e1e 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -212,6 +212,14 @@ (with-as (open "README.md" "r") fd (pass))) +(defn test-for-doodle [] + "NATIVE: test for-do" + (setf (, x y) (, 0 0)) + (foreach [- [1 2]] + (do + (setf x (+ x 1)) + (setf y (+ y 1)))) + (assert (= y x 2))) (defn test-comprehensions [] "NATIVE: test list comprehensions"