Skip to content

Commit

Permalink
#917 Static method fn
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 10, 2024
1 parent 82bf12b commit d07c0f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/sci/impl/evaluator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
(when (or (not env)
(not (contains? env sym)))
(let [sym (types/eval sym ctx bindings)
res (second (@utils/lookup ctx sym false))]
res (second
(@utils/lookup ctx sym false nil (qualified-symbol? sym)))]
(when-not #?(:cljs (instance? sci.impl.types/NodeR res)
:clj (instance? sci.impl.types.Eval res))
res)))))
Expand Down
14 changes: 3 additions & 11 deletions src/sci/impl/resolve.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@
[clazz #?(:clj sym-name
:cljs (.split (str sym-name) "."))]
{:sci.impl.analyzer/interop-ifn true})
#_(->Node
(interop/get-static-field clazz sym-name)
stack) #_(if (str/starts-with? (str sym-name) ".")
::TODO-return-IFn ;; that invokes instance method on class...
#_(let [meths (Reflector/getMethods clazz arg-count method false)])

(->Node
(interop/get-static-field clazz sym-name)
stack))
:cljs
(let [stack (assoc (meta sym)
:file @utils/current-file
Expand Down Expand Up @@ -162,7 +153,8 @@

(defn lookup
([ctx sym call?] (lookup ctx sym call? nil))
([ctx sym call? #?(:clj tag :cljs _tag)]
([ctx sym call? tag] (lookup ctx sym call? tag nil))
([ctx sym call? #?(:clj tag :cljs _tag) only-var?]
(let [bindings (faster/get-2 ctx :bindings)
track-mutable? (faster/get-2 ctx :deftype-fields)]
(or
Expand Down Expand Up @@ -197,7 +189,7 @@
mutable? (vary-meta assoc :mutable true))]
v))]
[k v]))
(when-let [kv (lookup* ctx sym call?)]
(when-let [kv (lookup* ctx sym call? only-var?)]
(when (:check-permissions ctx)
(check-permission! ctx sym kv))
kv)))))
Expand Down
24 changes: 14 additions & 10 deletions test/sci/interop_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,27 @@
:classes {'java.lang.Class {:class Class
:static-methods {'forName (fn [_Class _forName] :dude)}}}})))))

#?(:clj
(deftest clojure-1_12-interop-test
(is (= [1 2 3] (eval* "(map Integer/parseInt [\"1\" \"2\" \"3\"])")))))

(when-not tu/native?
(deftest exception-data
(testing "top-level interop forms have line and column data"
(letfn [(form-ex-data [form]
(try
(tu/eval* (str form) {:classes {:allow :all
#?@(:clj ['Long Long])}})
(is (= nil "shouldn't reach here"))
(catch #?(:clj Exception :cljs :default) e
(ex-data e))))]
(let [form-ex-data
(fn [form]
(try
(tu/eval* (str form) {:classes {:allow :all
#?@(:clj ['Long Long])}})
(is (= nil "shouldn't reach here") (str form))
(catch #?(:clj Exception :cljs :default) e
(ex-data e))))]
(testing "instance members"
(are [form]
(let [actual (form-ex-data form)]
(and (tu/submap? {:type :sci/error
:line 1
:column 1}
:line 1
:column 1}
actual)
(str/includes? (:message actual) "missingMem")))
'(. 3 missingMem) '(. 3 missingMem 1 2)
Expand All @@ -156,7 +160,7 @@
'(.missingMem Long) '(.missingMem Long 1 2)
'(Long/missingMem) '(Long/missingMem 1 2)
'(. Long -missingMem) '(.-missingMem Long)
'Long/missingMem '(Long/-missingMem))))))))
#_#_'Long/missingMem '(Long/-missingMem))))))))

(deftest syntax-test
(when-not tu/native?
Expand Down

0 comments on commit d07c0f1

Please sign in to comment.