summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Listopadov <andreyorst@gmail.com>2021-02-16 20:57:29 +0300
committerAndrey Listopadov <andreyorst@gmail.com>2021-02-16 20:57:29 +0300
commitc5ac672b4e0e83fa92d629216c3e07abc2756489 (patch)
treec2a7fe1eb3dc9be011937e92635b0da72dd5083e
parent7feb5aabe6e71ad6e65c72ca3cc977541c0991c4 (diff)
fix(core): check if nil is used as table key
-rw-r--r--init.fnl2
-rw-r--r--tests/core.fnl3
2 files changed, 4 insertions, 1 deletions
diff --git a/init.fnl b/init.fnl
index 7d5a7f9..4d67d9a 100644
--- a/init.fnl
+++ b/init.fnl
@@ -958,12 +958,14 @@ use."
(fn* core.assoc
"Associate key `k` with value `v` in `tbl`."
([tbl k v]
+ (assert (not (nil? k)) "attempt to use nil as key")
(setmetatable
(doto tbl (tset k v))
{:cljlib/type :table}))
([tbl k v & kvs]
(assert (= (% (length kvs) 2) 0)
(.. "no value supplied for key " (. kvs (length kvs))))
+ (assert (not (nil? k)) "attempt to use nil as key")
(tset tbl k v)
(var [k v] [nil nil])
(var (i k) (next kvs))
diff --git a/tests/core.fnl b/tests/core.fnl
index fe14670..063df03 100644
--- a/tests/core.fnl
+++ b/tests/core.fnl
@@ -721,7 +721,8 @@
(assert-eq (core.hash-map) {})
(assert-eq (core.hash-map :a 1) {:a 1})
(assert-eq (core.hash-map :a 1 :b 2 :c 3) {:a 1 :b 2 :c 3})
- (assert-eq (getmetatable (core.hash-map)) {:cljlib/type :table})))
+ (assert-eq (getmetatable (core.hash-map)) {:cljlib/type :table})
+ (assert-not (pcall core.hash-map nil 1))))
(deftest sets
(testing "hash-set"