I see we have some renewed interest in https://clojure.atlassian.net/browse/CLJ-2817 getting addressed (two Asks, 9 votes total). It has a patch but needs an updated patch to fix the merge order of metadata, per Ambrose. If someone creates and adds a new patch with that fix, could this be considered for 1.13?
Sure
@alexmiller Just a sanity check -- the following doesn't work (it's a reflective call) and we're not trying to fix it with CLJ-2817, right?
(defn ^String primfn-returns-string-1 [^long n]
(str n))
whereas this currently doesn't work but we expect CLJ-2817 to fix it:
(defn primfn-returns-string-2 ^String [^long n]
(str n))
I can't figure out an appropriate test to isolate the problem @ambrosebs highlighted in that ticket about the current patch (oh, and RT.meta(args) can be null so it can be the first arg to RT.conj() in that case).Revisiting this I'm not sure it's an actual issue, just maybe something worth noting. The current patch seems like the natural precedence order.
IIRC I was pointing out that the form
(defn ^Foo f ^Bar [])
now chooses Bar instead of Foo at invocation sites.Perhaps it's better described as a fix than a regression? I think the actual return type will be Bar at the primitive call site? Before it was incorrectly Foo.
No, I was wrong it doesn't seem to use Foo at all (reflection warning is on Object).
Clojure 1.12.4
user=> (set! *warn-on-reflection* true)
true
user=> (defn ^Integer foo ^String [^long n] (str n))
#'user/foo
user=> #(.length (foo 0))
Reflection warning, NO_SOURCE_PATH:1:2 - reference to field length on java.lang.Object can't be resolved.
#object[user$eval139$fn__140 0x997d532 "user$eval139$fn__140@997d532"]
So I don't think my concern was valid in the first place.Okay, that makes me feel better about not being able to create a test that differentiated the two metadata sites 🙂
I'd love to see this merged. I'm ready to tune the patch if it helps to fast-track it. But from what I gather, it is currently fine as it is.
https://ask.clojure.org/index.php/13501/primitive-type-hints-arguments-turns-the-return-value-object in question