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("catch")
|
||||||
@builds("except")
|
@builds("except")
|
||||||
def compile_catch_expression(self, expr):
|
def compile_catch_expression(self, expr):
|
||||||
expr.pop(0) # catch
|
catch = expr.pop(0) # catch
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exceptions = expr.pop(0)
|
exceptions = expr.pop(0)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
exceptions = []
|
exceptions = HyList()
|
||||||
# exceptions catch should be either:
|
# exceptions catch should be either:
|
||||||
# [[list of exceptions]]
|
# [[list of exceptions]]
|
||||||
# or
|
# or
|
||||||
@ -239,6 +239,8 @@ class HyASTCompiler(object):
|
|||||||
# [exception]
|
# [exception]
|
||||||
# or
|
# or
|
||||||
# []
|
# []
|
||||||
|
if not isinstance(exceptions, HyList):
|
||||||
|
raise TypeError("`%s' exceptions list is not a list" % catch)
|
||||||
if len(exceptions) > 2:
|
if len(exceptions) > 2:
|
||||||
raise TypeError("`catch' exceptions list is too long")
|
raise TypeError("`catch' exceptions list is too long")
|
||||||
|
|
||||||
|
@ -134,6 +134,7 @@ def test_ast_good_catch():
|
|||||||
def test_ast_bad_catch():
|
def test_ast_bad_catch():
|
||||||
"Make sure AST can't compile invalid catch"
|
"Make sure AST can't compile invalid catch"
|
||||||
cant_compile("(catch 1)")
|
cant_compile("(catch 1)")
|
||||||
|
cant_compile("(catch \"A\")")
|
||||||
cant_compile("(catch [1 3])")
|
cant_compile("(catch [1 3])")
|
||||||
cant_compile("(catch [x [FooBar] BarBar])")
|
cant_compile("(catch [x [FooBar] BarBar])")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user