except/catch: check exceptions list type
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
4e61ae59fd
commit
dd90272129
@ -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")
|
||||
|
||||
|
@ -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])")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user