The following code gives me a reflection warning in spite of the type hint.
(set! *warn-on-reflection* true)
(IllegalArgumentException.
^String (with-out-str (print "hi")))
The warning:
Reflection warning ...
call to java.lang.IllegalArgumentException ctor
can't be resolved.
The code has been extracted and simplified from a more complex example where pretty printing an arbitrary object is performed within the with-out-str. I am using Clojure 1.10.0.
This is CLJ-865. It's not specific to with-out-str: adding a type hint to any form which is a macro invocation will typically discard it. The typical workaround is the one in your answer: define a local saving the value, artificially introducing an non-macro form to annotate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With