From 7c3477e7388a488a0f1f10b677e195b64a3b7329 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Sat, 7 Apr 2018 21:58:59 -0400 Subject: [PATCH] Fix a bug where the compiler doesn't properly handle unquote-splice Added test coverage as well --- NEWS.rst | 1 + hy/compiler.py | 2 +- tests/compilers/test_ast.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index cabc57b..4270da5 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -51,6 +51,7 @@ Bug Fixes * Fixed a REPL crash caused by illegle unicode escape string inputs * `NaN` can no longer create an infinite loop during macro-expansion * Fixed a bug that caused `try` to drop expressions +* Fixed a bug where the compiler didn't properly compile `unquote-splice` Misc. Improvements ---------------------------- diff --git a/hy/compiler.py b/hy/compiler.py index e567d8d..cb2a3d1 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -723,7 +723,7 @@ class HyASTCompiler(object): ret.add_imports("hy", imports) return ret - @builds("unquote", "unquote-splicing") + @builds("unquote", "unquote-splice") def compile_unquote(self, expr): raise HyTypeError(expr, "`%s' can't be used at the top-level" % expr[0]) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index c8d2999..9b9b16e 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -588,6 +588,16 @@ def test_setv_builtins(): """) +def test_top_level_unquote(): + with pytest.raises(HyTypeError) as excinfo: + can_compile("(unquote)") + assert excinfo.value.message == "`unquote' can't be used at the top-level" + + with pytest.raises(HyTypeError) as excinfo: + can_compile("(unquote-splice)") + assert excinfo.value.message == "`unquote-splice' can't be used at the top-level" + + def test_lots_of_comment_lines(): # https://github.com/hylang/hy/issues/1313 can_compile(1000 * ";\n")