core.macros: Fix a for corner case
In case for doesn't get a body, raise the appropriate, descriptive error instead of an IndexOutOfBounds one. Also updated the failing test case. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
parent
a0cb250f24
commit
439fa6eb17
@ -98,6 +98,8 @@
|
|||||||
(for* [y bar]
|
(for* [y bar]
|
||||||
baz))"
|
baz))"
|
||||||
(setv body (list body))
|
(setv body (list body))
|
||||||
|
(if (empty? body)
|
||||||
|
(macro-error None "`for' requires a body to evaluate"))
|
||||||
(setv lst (get body -1))
|
(setv lst (get body -1))
|
||||||
(setv belse (if (and (isinstance lst HyExpression) (= (get lst 0) "else"))
|
(setv belse (if (and (isinstance lst HyExpression) (= (get lst 0) "else"))
|
||||||
[(body.pop)]
|
[(body.pop)]
|
||||||
|
@ -484,7 +484,7 @@ def test_for_compile_error():
|
|||||||
assert(False)
|
assert(False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
can_compile("(fn [] (for [x]))")
|
can_compile("(fn [] (for [x] x))")
|
||||||
except HyTypeError as e:
|
except HyTypeError as e:
|
||||||
assert(e.message == "`for' requires an even number of args.")
|
assert(e.message == "`for' requires an even number of args.")
|
||||||
else:
|
else:
|
||||||
@ -497,6 +497,13 @@ def test_for_compile_error():
|
|||||||
else:
|
else:
|
||||||
assert(False)
|
assert(False)
|
||||||
|
|
||||||
|
try:
|
||||||
|
can_compile("(fn [] (for [x xx] (else 1)))")
|
||||||
|
except HyTypeError as e:
|
||||||
|
assert(e.message == "`for' requires a body to evaluate")
|
||||||
|
else:
|
||||||
|
assert(False)
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_access():
|
def test_attribute_access():
|
||||||
"""Ensure attribute access compiles correctly"""
|
"""Ensure attribute access compiles correctly"""
|
||||||
|
Loading…
Reference in New Issue
Block a user