Make setv
return None for more types of rvalues
This commit is contained in:
parent
286d568959
commit
491b474e7f
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user