Skip to content

Commit bbe159a

Browse files
committed
handle string type hints
1 parent c8248ec commit bbe159a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/sci/impl/interop.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@
161161

162162
#?(:clj
163163
(defn resolve-type-hint [ctx sym]
164-
(or (get prim->class sym)
165-
(:class (resolve-class-opts ctx sym)))))
164+
(if (string? sym) (Class/forName sym)
165+
(or (get prim->class sym)
166+
(:class (resolve-class-opts ctx sym))))))
166167

167168
#?(:clj
168169
(def ->array-class

test/sci/interop_test.cljc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@
334334
(is (= 1 (tu/eval* "(let [j #js {:a (fn [] 1)}] (j.a))" nil)))))
335335

336336
(deftest type-hint-test
337+
(testing "string type hints"
338+
(is (string? (sci/eval-string "(defn read-string [^\"[B\" v] (String. v)) (read-string \"1\")"))))
337339
(testing "type hinting with runnable returns nil on futuretask get"
338340
#?(:clj
339341
(let [config {:classes {'java.util.concurrent.Executors java.util.concurrent.Executors 'java.util.concurrent.ThreadPoolExecutor java.util.concurrent.ThreadPoolExecutor 'java.util.concurrent.Callable java.util.concurrent.Callable 'java.util.concurrent.FutureTask java.util.concurrent.FutureTask 'java.lang.Runnable java.lang.Runnable}}]

0 commit comments

Comments
 (0)