From d3520e56407d037de0f2725c793c7a24dd209a2b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 10 Aug 2015 14:19:19 +0200 Subject: [PATCH] Trying to setv a callable should raise a nice error When trying to setv a callable, raise an error instead of showing the user an incredibly ugly backtrace. Closes #532. Signed-off-by: Gergely Nagy --- hy/compiler.py | 4 ++++ tests/compilers/test_ast.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index 8e9893c..fac4cfa 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -2004,6 +2004,10 @@ class HyASTCompiler(object): result = self.compile(result) ld_name = self.compile(name) + if isinstance(ld_name.expr, ast.Call): + raise HyTypeError(name, + "Can't assign to a callable: `%s'" % str_name) + if result.temp_variables \ and isinstance(name, HyString) \ and '.' not in name: diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 4491f83..c68c609 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -519,3 +519,9 @@ def test_attribute_access(): def test_cons_correct(): """Ensure cons gets compiled correctly""" can_compile("(cons a b)") + + +def test_bad_setv(): + """Ensure setv handles error cases""" + cant_compile("(setv if 1)") + cant_compile("(setv (a b) [1 2])")