kkinnear / zprint

Executables, uberjar, and library to beautifully format Clojure and Clojurescript source code and s-expressions.
MIT License
556 stars 48 forks source link

Clojure 1.12 Array class syntax support #334

Open PEZ opened 1 month ago

PEZ commented 1 month ago

Hi! Clojure 1.12 adds new Array class syntax. Example:

(type (make-array Long 10)) => java.lang.Long/1

Unfortunatelly zprint croaks on this:

Invalid symbol: java.lang.Long/1.

And this makes Calva sad.

I haven't checked if this is upstream on rewrite-clj, but adding here to put it on your radar, unless it wasn't already.

PEZ commented 1 month ago

I now checked the rewrite-clj issue tracker and couldn't find anything about this. But the issue search engine isn't exactly stellar, so I may just have missed it.

PEZ commented 1 month ago

Hmmm... It is not this simple. This works fine:

  #_{zprint/zprint {:mvn/version "1.2.9"}}
  (require '[zprint.core :as zp])
  (zp/czprint-str "^[Long] a" 40 {:parse-string-all? true})
  ;;=> "^[Long] a"
  (zp/czprint-str "^Long/1 a" 40 {:parse-string-all? true})
  ;;=> "^Long/1 a"

I tried this in Clojure. So it may have something to do with that Calva uses the ClojureScript libraries. (And Clojure pre-11, come to think of it.) I'll go check from that end of things and see if I have just bothered you for no reason.

PEZ commented 1 month ago

Hello again. I'm sorry for this getting messy. I now think I know why the above test didn't reproduce the problem. Right before that, I had tried this:

  #_{rewrite-clj/rewrite-clj {:mvn/version "1.1.48"}}
  (require '[rewrite-clj.zip :as z])
  (-> (z/of-string "^[Long] a")
      z/sexpr)
  (-> (z/of-string "^Long/1 a")
      z/sexpr)

And that made zprint use rewrite-clj 1.1.48. And we can read in the CHANGELOG for rewrite-cljs on v1.1.48 (which I of course should have done before I hunted in the issue tracker 🤦):

Add support for Clojure 1.12 array class syntax

Using zprint without first requiring the fixed rewrite-clj reproduces the problem.

kkinnear commented 1 month ago

Thank you very much for letting me know about this. I had missed this change in Clojure 1.12, and the corresponding upgrade required in rewrite-clj. In my tests as well, rewrite-clj 1.1.48 solves this problem. I will hasten the release of zprint 1.3.0 with the new rewrite-clj to to make this solution available to everyone. Again, many thanks!