diff --git a/hy/compiler.py b/hy/compiler.py index 76b266a..7f56b40 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -223,12 +223,12 @@ class HyASTCompiler(object): @builds("catch") @builds("except") def compile_catch_expression(self, expr): - expr.pop(0) # catch + catch = expr.pop(0) # catch try: exceptions = expr.pop(0) except IndexError: - exceptions = [] + exceptions = HyList() # exceptions catch should be either: # [[list of exceptions]] # or @@ -239,6 +239,8 @@ class HyASTCompiler(object): # [exception] # or # [] + if not isinstance(exceptions, HyList): + raise TypeError("`%s' exceptions list is not a list" % catch) if len(exceptions) > 2: raise TypeError("`catch' exceptions list is too long") diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index f839feb..e9272a3 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -134,6 +134,7 @@ def test_ast_good_catch(): def test_ast_bad_catch(): "Make sure AST can't compile invalid catch" cant_compile("(catch 1)") + cant_compile("(catch \"A\")") cant_compile("(catch [1 3])") cant_compile("(catch [x [FooBar] BarBar])")