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 isinstance(name, HyString) \
|
||||||
and '.' not in name:
|
and '.' not in name:
|
||||||
result.rename(name)
|
result.rename(name)
|
||||||
|
# Throw away .expr to ensure that (setv ...) returns None.
|
||||||
|
result.expr = None
|
||||||
else:
|
else:
|
||||||
st_name = self._storeize(name, ld_name)
|
st_name = self._storeize(name, ld_name)
|
||||||
result += ast.Assign(
|
result += ast.Assign(
|
||||||
|
@ -108,6 +108,18 @@
|
|||||||
(assert (= q 12))
|
(assert (= q 12))
|
||||||
(assert (none? p))
|
(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
|
; https://github.com/hylang/hy/issues/1052
|
||||||
(assert (none? (setv (get {} "x") 42)))
|
(assert (none? (setv (get {} "x") 42)))
|
||||||
(setv l [])
|
(setv l [])
|
||||||
@ -119,6 +131,7 @@
|
|||||||
(assert (not (hasattr x "eggs")))
|
(assert (not (hasattr x "eggs")))
|
||||||
(assert (= l [["eggs" "ham"]])))
|
(assert (= l [["eggs" "ham"]])))
|
||||||
|
|
||||||
|
|
||||||
(defn test-store-errors []
|
(defn test-store-errors []
|
||||||
"NATIVE: test that setv raises the correct errors when given wrong argument types"
|
"NATIVE: test that setv raises the correct errors when given wrong argument types"
|
||||||
(try
|
(try
|
||||||
|
Loading…
Reference in New Issue
Block a user