From 699f9622d7662af42c2e0ed409ec2ff4f1c9e2a9 Mon Sep 17 00:00:00 2001 From: Techcable Date: Fri, 26 Aug 2022 14:24:54 -0700 Subject: [PATCH] Warn about index-of type errors when not iterable This is just documentation of existing behavior, it does not change anything. The reason index-of throws a type error on non-iterable types is because `next` does. This is hardcoded into the JOP_NEXT opcode (see src/core/value.c:janet_next_impl). Unfortunately, there is currently no corresponding `iterable?` check. --- src/boot/boot.janet | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index bbc9de5c..1609facc 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1072,7 +1072,9 @@ (defn index-of ``Find the first key associated with a value x in a data structure, acting like a reverse lookup. Will not look at table prototypes. - Returns `dflt` if not found.`` + Returns `dflt` if not found. + + This will throw an error if `ind` is not iterable.`` [x ind &opt dflt] (var k (next ind nil)) (var ret dflt)