diff --git a/hy/compiler.py b/hy/compiler.py index 5d15cf4..3c5ab84 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1017,13 +1017,21 @@ class HyASTCompiler(object): return ret @builds("global") - @checkargs(1) + @checkargs(min=1) def compile_global_expression(self, expr): expr.pop(0) # global - e = expr.pop(0) - return ast.Global(names=[ast_str(e)], - lineno=e.start_line, - col_offset=e.start_column) + names = [] + while len(expr) > 0: + identifier = expr.pop(0) + name = ast_str(identifier) + names.append(name) + if not isinstance(identifier, HySymbol): + raise HyTypeError(identifier, "(global) arguments must " + " be Symbols") + + return ast.Global(names=names, + lineno=expr.start_line, + col_offset=expr.start_column) @builds("yield") @checkargs(max=1) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 9d8cf69..7818447 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -211,12 +211,13 @@ def test_ast_bad_assert(): def test_ast_good_global(): "Make sure AST can compile valid global" can_compile("(global a)") + can_compile("(global foo bar)") def test_ast_bad_global(): "Make sure AST can't compile invalid global" cant_compile("(global)") - cant_compile("(global foo bar)") + cant_compile("(global (foo))") def test_ast_good_defclass():