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 <algernon@madhouse-project.org>
This commit is contained in:
Gergely Nagy 2015-08-10 14:19:19 +02:00
parent 2665b316cf
commit d3520e5640
No known key found for this signature in database
GPG Key ID: 0A083C5F06E0DD42
2 changed files with 10 additions and 0 deletions

View File

@ -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:

View File

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