Make setv return None for more types of rvalues

This commit is contained in:
Kodi Arfer 2017-04-06 14:41:11 -07:00 committed by Tuukka Turto
parent 286d568959
commit 491b474e7f
2 changed files with 15 additions and 0 deletions

View File

@ -2181,6 +2181,8 @@ class HyASTCompiler(object):
and isinstance(name, HyString) \
and '.' not in name:
result.rename(name)
# Throw away .expr to ensure that (setv ...) returns None.
result.expr = None
else:
st_name = self._storeize(name, ld_name)
result += ast.Assign(

View File

@ -108,6 +108,18 @@
(assert (= q 12))
(assert (none? p))
(assert (none? (setv x (defn phooey [] (setv p 1) (+ p 6)))))
(assert (none? (setv x (defclass C))))
(assert (none? (setv x (for [i (range 3)] i (inc i)))))
(assert (none? (setv x (assert True))))
(assert (none? (setv x (with [(open "README.md" "r")] 3))))
(assert (= x 3))
(assert (none? (setv x (try (/ 1 2) (except [ZeroDivisionError] "E1")))))
(assert (= x .5))
(assert (none? (setv x (try (/ 1 0) (except [ZeroDivisionError] "E2")))))
(assert (= x "E2"))
; https://github.com/hylang/hy/issues/1052
(assert (none? (setv (get {} "x") 42)))
(setv l [])
@ -119,6 +131,7 @@
(assert (not (hasattr x "eggs")))
(assert (= l [["eggs" "ham"]])))
(defn test-store-errors []
"NATIVE: test that setv raises the correct errors when given wrong argument types"
(try