Skip to content

Commit d40875b

Browse files
committed
yes
1 parent 38cec03 commit d40875b

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

src/sci/impl/analyzer.cljc

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,17 +1464,17 @@
14641464
(defn analyze-call [ctx expr m top-level?]
14651465
(with-top-level-loc top-level? m
14661466
(try
1467-
(let [f (first expr)]
1468-
(cond (symbol? f)
1469-
(let [fsym f
1467+
(let [f* (first expr)]
1468+
(cond (symbol? f*)
1469+
(let [fsym f*
14701470
;; in call position Clojure prioritizes special symbols over
14711471
;; bindings
1472-
special-sym (get special-syms f)
1472+
special-sym (get special-syms f*)
14731473
_ (when (and special-sym
14741474
(:check-permissions ctx))
1475-
(resolve/check-permission! ctx f [special-sym nil]))
1475+
(resolve/check-permission! ctx f* [special-sym nil]))
14761476
f (or special-sym
1477-
(resolve/resolve-symbol ctx f true))
1477+
(resolve/resolve-symbol ctx f* true))
14781478
f-meta (meta f)
14791479
eval? (and f-meta (:sci.impl/op f-meta))
14801480
fast-path (-> f-meta :sci.impl/fast-path)
@@ -1555,15 +1555,23 @@
15551555
:sci.impl/f-meta f-meta)
15561556
^"[Ljava.lang.Class;" arg-types (when (pos? arg-count)
15571557
(make-array Class arg-count))
1558-
has-types? (volatile! nil)]
1558+
has-types? (volatile! nil)
1559+
]
15591560
(when arg-types
1560-
(areduce args idx _ret nil
1561-
(let [arg (aget args idx)
1562-
arg-meta (meta arg)]
1563-
(when-let [t (:tag arg-meta)]
1564-
(when-let [t (interop/resolve-type-hint ctx t)]
1565-
(do (vreset! has-types? true)
1566-
(aset arg-types idx t)))))))
1561+
(or (when-let [param-tags (-> f* (some-> meta :param-tags))]
1562+
(vreset! has-types? true)
1563+
;; TODO: take into account wildcard _ class!
1564+
(areduce arg-types idx _ret nil
1565+
(when-let [t (nth param-tags idx)]
1566+
(when-let [t (interop/resolve-type-hint ctx t)]
1567+
(aset arg-types idx t)))))
1568+
(areduce args idx _ret nil
1569+
(let [arg (aget args idx)
1570+
arg-meta (meta arg)]
1571+
(when-let [t (:tag arg-meta)]
1572+
(when-let [t (interop/resolve-type-hint ctx t)]
1573+
(do (vreset! has-types? true)
1574+
(aset arg-types idx t))))))))
15671575
(sci.impl.types/->Node
15681576
(let [obj (sci.impl.types/eval obj ctx bindings)]
15691577
(interop/invoke-instance-method ctx bindings obj clazz
@@ -1656,23 +1664,23 @@
16561664
:file @utils/current-file
16571665
:sci.impl/f-meta f-meta)]
16581666
(sci.impl.types/->Node nil stack)))))))
1659-
(keyword? f)
1667+
(keyword? f*)
16601668
(let [children (analyze-children ctx (rest expr))
16611669
ccount (count children)]
16621670
(case ccount
16631671
1 (let [arg (nth children 0)]
16641672
(sci.impl.types/->Node
1665-
(f (t/eval arg ctx bindings))
1673+
(f* (t/eval arg ctx bindings))
16661674
nil))
16671675
2 (let [arg0 (nth children 0)
16681676
arg1 (nth children 1)]
16691677
(sci.impl.types/->Node
1670-
(f (t/eval arg0 ctx bindings)
1678+
(f* (t/eval arg0 ctx bindings)
16711679
(t/eval arg1 ctx bindings))
16721680
nil))
1673-
(throw-error-with-location (str "Wrong number of args (" ccount ") passed to: " f) expr)))
1681+
(throw-error-with-location (str "Wrong number of args (" ccount ") passed to: " f*) expr)))
16741682
:else
1675-
(let [f (analyze ctx f)
1683+
(let [f (analyze ctx f*)
16761684
children (analyze-children ctx (rest expr))
16771685
stack (assoc m
16781686
:ns @utils/current-ns

test/sci/interop_test.cljc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,13 @@
374374
(testing "type hinting on fn expression as argument with Callable returns nil on futuretask get"
375375
(is (= 3 (sci/eval-string "(def fut (.submit (java.util.concurrent.Executors/newCachedThreadPool) ^java.util.concurrent.Callable (fn [] 3))) (.get fut)" type-hint-config))))
376376
(testing "similar cases but with qualified interop"
377-
(is (nil? (sci/eval-string "(def ^java.util.concurrent.ExecutorService thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
378-
@(java.util.concurrent.ExecutorService/.submit thread-pool ^Runnable (fn [] 3))"
379-
type-hint-config)))
380-
(is (= 3 (sci/eval-string "(def ^java.util.concurrent.ExecutorService thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
381-
@(java.util.concurrent.ExecutorService/.submit thread-pool ^Callable (fn [] 3))"
382-
type-hint-config)))
383-
(is (nil? (sci/eval-string "(def ^java.util.concurrent.ExecutorService thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
384-
@((identity ^[Runnable] java.util.concurrent.ExecutorService/.submit) thread-pool (fn [] 3))"
385-
type-hint-config)))
386-
(is (= 3 (sci/eval-string "(def ^java.util.concurrent.ExecutorService thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
387-
@((identity ^[Callable] java.util.concurrent.ExecutorService/.submit) thread-pool (fn [] 3))"
388-
type-hint-config)))))
377+
(is (= [nil nil 3 3] (sci/eval-string "(def ^java.util.concurrent.ExecutorService thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
378+
[
379+
@(java.util.concurrent.ExecutorService/.submit thread-pool ^Runnable (fn [] 3))
380+
@(^[Runnable] java.util.concurrent.ExecutorService/.submit thread-pool (fn [] 3))
381+
@(java.util.concurrent.ExecutorService/.submit thread-pool ^Callable (fn [] 3))
382+
@(^[Callable ]java.util.concurrent.ExecutorService/.submit thread-pool (fn [] 3))]"
383+
type-hint-config)))))
389384
(testing "type hint on interop argument"
390385
;; this test assumes clojure/core.clj comes from a jar file
391386
;; the test will fail when not processing the type hint on the interop argument

0 commit comments

Comments
 (0)