Skip to content

Commit

Permalink
Update to Java commit ad54fec (2024.08.28): CLJ-2881: Making asm-type…
Browse files Browse the repository at this point in the history
… function array class symbol aware.

ClojureCLR has a parallel problem in genclass.
  • Loading branch information
dmiller committed Dec 4, 2024
1 parent fc1d893 commit 2992c9a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
30 changes: 28 additions & 2 deletions Clojure/Clojure.Source/clojure/genclass.clj
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,36 @@
;;;;;;;;;;;;;;;;;;;; gen-interface ;;;;;;;;;;;;;;;;;;;;;;
;; based on original contribution by Chris Houser

#_(defn- ^Type asm-type
"Returns an asm Type object for c, which may be a primitive class
(such as Integer/TYPE), any other class (such as Double), or a
fully-qualified class name given as a string or symbol
(such as 'java.lang.String)"
[c]
(let [c (or (and (symbol? c) (clojure.lang.Compiler$HostExpr/maybeArrayClass c)) c)]
(if (or (instance? Class c) (prim->class c))
(Type/getType (the-class c))
(let [strx (str c)]
(Type/getObjectType
(.replace (if (some #{\. \[} strx)
strx
(str "java.lang." strx))
"." "/"))))))

(defn- the-class-for-definterface [c]
(let [x (or (and (symbol? c) (clojure.lang.CljCompiler.Ast.HostExpr/MaybeArrayType c))
c)]
(the-class x)))

(defn- the-class-maybe-by-ref-for-definterface [x]
(cond
(seq? x) (list (first x) (the-class-for-definterface (second x))) ; (by-ref v)
:else (the-class-for-definterface x)))

(defn- generate-interface
[{:keys [name extends methods]}]
(let [extendTypes (map the-class extends)
methodSigs (map (fn [[mname pclasses rclass pmetas]] [mname (map the-class-maybe-by-ref pclasses) (the-class rclass) pmetas]) methods)]
(let [extendTypes (map the-class extends)
methodSigs (map (fn [[mname pclasses rclass pmetas]] [mname (map the-class-maybe-by-ref-for-definterface pclasses) (the-class-for-definterface rclass) pmetas]) methods)]
(clojure.lang.GenInterface/GenerateInterface (str name) (extract-attributes (meta name)) extendTypes methodSigs)))


Expand Down
15 changes: 14 additions & 1 deletion Clojure/Clojure.Tests/clojure/test_clojure/array_symbols.clj
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,17 @@
(is (thrown? Exception (read-string "String/1:")))
(is (thrown? Exception (read-string "String/0")))
(is (thrown? Exception (read-string "String/42")))
(is (thrown? Exception (eval '(deftype Foo/2 [a]))))))
(is (thrown? Exception (eval '(deftype Foo/2 [a]))))))

(definterface ArrayClassSymbolFoo (^String/1 bar []))
(definterface ArrayClassSymbolFooAsHint (^ArrayClassSymbolFoo/1 baz []))
(deftest test-definterface-acs
(testing "definterface"
(let [obj (reify ArrayClassSymbolFoo (bar [this] (into-array String ["a"])))]
(is (= ["a"] (seq (.bar obj)))))
(let [obj (reify ArrayClassSymbolFooAsHint
(baz [this]
(into-array ArrayClassSymbolFoo [(reify ArrayClassSymbolFoo
(bar [this] (into-array String ["a"])))])))]
(is (= ["a"] (let [^ArrayClassSymbolFoo acsf (first (.baz obj))]
(seq (.bar acsf))))))))

0 comments on commit 2992c9a

Please sign in to comment.