diff --git a/src/sci/impl/analyzer.cljc b/src/sci/impl/analyzer.cljc index c06da5d7..99dff8fc 100644 --- a/src/sci/impl/analyzer.cljc +++ b/src/sci/impl/analyzer.cljc @@ -1803,21 +1803,30 @@ #?(:clj (defn analyze-interop-ifn [_ctx expr [^Class clazz meth]] - (let [stack (assoc (meta expr) + (let [meth (str meth) + stack (assoc (meta expr) :ns @utils/current-ns :file @utils/current-file)] - (if-let [_fld (try (Reflector/getStaticField ^Class clazz ^String (str meth)) + (if-let [_fld (try (Reflector/getStaticField ^Class clazz ^String meth) (catch IllegalArgumentException _ nil))] (sci.impl.types/->Node - (interop/get-static-field clazz (str meth)) - stack) - (sci.impl.types/->Node - (fn [& args] - (Reflector/invokeStaticMethod - (.getName clazz) (str meth) - ^objects (into-array Object args))) - stack))))) + (interop/get-static-field clazz meth) + stack) + (if (str/starts-with? meth ".") + (let [meth (subs meth 1)] + (sci.impl.types/->Node + (fn [obj & args] + (Reflector/invokeInstanceMethod + obj meth + ^objects (into-array Object args))) + stack)) + (sci.impl.types/->Node + (fn [& args] + (Reflector/invokeStaticMethod + clazz meth + ^objects (into-array Object args))) + stack)))))) #?(:clj (comment diff --git a/src/sci/impl/resolve.cljc b/src/sci/impl/resolve.cljc index 85d82e3f..28aba13d 100644 --- a/src/sci/impl/resolve.cljc +++ b/src/sci/impl/resolve.cljc @@ -67,13 +67,8 @@ :cljs (.split (str sym-name) "."))] {:sci.impl.analyzer/static-access true}) #?(:clj - ;; TODO: - ;; - [ ] if sym-name doesn't start with dot, it might be a static method which we need to turn into an IFn - ;; - [ ] but if it's a field, we still need to do the field call - ;; - [ ] if sym-name starts with dot, it's def. a method call which we need to create an IFn for (with-meta - [clazz #?(:clj sym-name - :cljs (.split (str sym-name) "."))] + [clazz sym-name] {:sci.impl.analyzer/interop-ifn true}) :cljs (let [stack (assoc (meta sym) diff --git a/test/sci/interop_test.cljc b/test/sci/interop_test.cljc index e5de05a0..ee65b370 100644 --- a/test/sci/interop_test.cljc +++ b/test/sci/interop_test.cljc @@ -122,7 +122,8 @@ #?(:clj (deftest clojure-1_12-interop-test - (is (= [1 2 3] (eval* "(map Integer/parseInt [\"1\" \"2\" \"3\"])"))))) + (is (= [1 2 3] (eval* "(map Integer/parseInt [\"1\" \"2\" \"3\"])"))) + (is (= [1 2 3] (eval* "(map String/.length [\"1\" \"22\" \"333\"])"))))) (when-not tu/native? (deftest exception-data