Welcome! Please see the About page for a little more info on how this works.

+4 votes
in Compiler by
closed by

Noticed by user yuhan in slack https://clojurians.slack.com/archives/C03S1KBA2/p1724499452475139

❯ clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.12.0-rc1"}}}'
Clojure 1.12.0-rc1
user=> (definterface Foo (^String/1 bar []))
user.Foo
user=> (reify Foo (bar [this]))
Syntax error (ClassNotFoundException) compiling reify* at (REPL:1:1).
java.lang.String.1
user=>
closed with the note: Releasing in 1.12.0-rc2

1 Answer

0 votes
by

Thanks for helping post the question!

For additional context, I noticed that defprotocol generates a valid interface given the same metadata tags, because the generated methods are dynamically typed, with the tags only being placed as type hints in the protocol map.

user=> (defprotocol PFoo (^String/1 bar [this]))
PFoo
user=> (reify user.PFoo (bar [this] :ok))
#object[user$eval196$reify__197 0x64a9d48c "user$eval196$reify__197@64a9d48c"]
user=> (bar *1)
:ok
user=> (first (.getMethods (:on-interface PFoo)))
#object[java.lang.reflect.Method 0x35178483 "public abstract java.lang.Object user.PFoo.bar()"]

Although the fact that it produces an unreadable symbol feels just as wrong:

user=> (:sigs PFoo)
{:bar {:tag [Ljava.lang.String;, :name bar, :arglists ([this]), :doc nil}}
user=> (get-in PFoo [:sigs :bar :tag])
[Ljava.lang.String;
user=> (class *1) ; oh no
clojure.lang.Symbol
by
Thanks! Just for clarity, in my last sentence above I meant "unreadable" in the sense of syntactically non-roundtrippable: here's a standalone repro
    
    user=> (defprotocol P (^int/5 oops [this]))
    P
    user=> (get-in P [:sigs :oops])
    {:tag [[[[[I, :name oops, :arglists ([this]), :doc nil}
    user=> (read-string (pr-str *1))
    Execution error at user/eval162 (REPL:1).
    Unmatched delimiter: }

That `[[[[I` symbol should probably be coerced to a string or stored as the original syntax (is the latter considered the canonical representation now?)
by
Thanks for the repro. I think that should be a different ticket. I'll put one together ASAP.
...