except/catch: check exceptions list type

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-04-09 16:56:45 +02:00
parent 4e61ae59fd
commit dd90272129
2 changed files with 5 additions and 2 deletions

View File

@ -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")

View File

@ -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])")