Fix a bug where the compiler doesn't properly handle unquote-splice

Added test coverage as well
This commit is contained in:
Simon Gomizelj 2018-04-07 21:58:59 -04:00 committed by Kodi Arfer
parent 7e1b890d7c
commit 7c3477e738
3 changed files with 12 additions and 1 deletions

View File

@ -51,6 +51,7 @@ Bug Fixes
* Fixed a REPL crash caused by illegle unicode escape string inputs * Fixed a REPL crash caused by illegle unicode escape string inputs
* `NaN` can no longer create an infinite loop during macro-expansion * `NaN` can no longer create an infinite loop during macro-expansion
* Fixed a bug that caused `try` to drop expressions * Fixed a bug that caused `try` to drop expressions
* Fixed a bug where the compiler didn't properly compile `unquote-splice`
Misc. Improvements Misc. Improvements
---------------------------- ----------------------------

View File

@ -723,7 +723,7 @@ class HyASTCompiler(object):
ret.add_imports("hy", imports) ret.add_imports("hy", imports)
return ret return ret
@builds("unquote", "unquote-splicing") @builds("unquote", "unquote-splice")
def compile_unquote(self, expr): def compile_unquote(self, expr):
raise HyTypeError(expr, raise HyTypeError(expr,
"`%s' can't be used at the top-level" % expr[0]) "`%s' can't be used at the top-level" % expr[0])

View File

@ -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(): def test_lots_of_comment_lines():
# https://github.com/hylang/hy/issues/1313 # https://github.com/hylang/hy/issues/1313
can_compile(1000 * ";\n") can_compile(1000 * ";\n")