Fork me on GitHub
#clojure
<
2024-04-29
>
seancorfield18:04:57

Clojure 1.12 Alpha 10 method values question in ๐Ÿงต

โค๏ธ 2
seancorfield18:04:38

We've updated to Alpha 10 at work (test suite passes, deploying to Staging right now). We were on Alpha 9 before. The following code worked on Alpha 9 with no reflection warnings:

(let [[y m] ((juxt java.time.OffsetDateTime/getYear
                     java.time.OffsetDateTime/getMonthValue)
               when)
    ...)
but when I updated it for Alpha 10, it required param-tags to avoid reflection:
(let [[y m] ((juxt ^[] OffsetDateTime/.getYear
                     ^[] OffsetDateTime/.getMonthValue)
               when)
    ...)
so I was a bit surprised by that. Did the method selection process change (as well as the syntax)?

Alex Miller (Clojure team)18:04:51

yes, many details of the implementation changed but let me read this more carefully

ghadi18:04:00

presumably an ODT

ghadi18:04:13

OffsetDateTime

seancorfield18:04:31

java.time.OffsetDateTime -- it isn't hinted (as an argument) but it is always that type.

Alex Miller (Clojure team)18:04:02

since this is an instance method, the type of the target object shouldn't matter, only the time of the class on the method symbol

Alex Miller (Clojure team)18:04:19

doesn't make sense to me why that should need param tags

seancorfield18:04:44

Yeah, seemed odd since getYear() has no overloads.

Alex Miller (Clojure team)18:04:39

(defn f [v] (OffsetDateTime/.getYear v))
seems like a sufficient repro

seancorfield18:04:49

Without param-tags:

Reflection warning, /home/sean/workspace/wsmain/bases/admin/src/ws/admin/model/reporting.clj:24:1 - call to method getYear can't be resolved (target class is unknown).

Reflection warning, /home/sean/workspace/wsmain/bases/admin/src/ws/admin/model/reporting.clj:24:1 - call to method getMonthValue can't be resolved (target class is unknown).

seancorfield18:04:19

LMK if you need any extra deets.

Alex Miller (Clojure team)18:04:39

ah, we've found it, thx

Alex Miller (Clojure team)18:04:22

it's using the target object class in one spot instead of the qualifying class as it should

seancorfield18:04:33

Yay! I found a bug! ๐Ÿ™‚

๐Ÿ™ 8
๐ŸŽ‰ 20
Alex Miller (Clojure team)18:04:06

and one sufficiently hard to find because it will still work reflectively (so doesn't trigger test failures in our regressions)

seancorfield18:04:27

That's why we require (set! *warn-on-reflection* true) in all our source files and fail the build if it's missing and if we get a reflection warning ๐Ÿ™‚

๐Ÿ‘ 1
Alex Miller (Clojure team)18:04:24

I think in all cases the new qualified methods with instance method and no param-tags will thus reflect

Alex Miller (Clojure team)18:04:52

which btw, we are going to put some work on 1.13 to look at how to support that use case better ("error on reflect")

๐Ÿ‘ 2
๐Ÿ™Œ 2
1
seancorfield18:04:10

That explains why .File/.isDirectory worked without a param-tag hint -- it's in our build.clj which doesn't have the reflection warning set... ๐Ÿ™‚

seancorfield18:04:10

OK, Alpha 10 is officially on Staging for testing and potential deployment to Production!

๐ŸŽ‰ 4
thomas08:04:57

I love it that that Clojure users have so much confidence in updated from the (core) team that they are willing to run Alpha code into prod. Testament to the team ๐Ÿ™

seancorfield17:04:11

We've run alpha/beta builds in production since we first took Clojure 1.3 to production in 2011 (alpha 7 or 8 back then, I believe). I strongly believe more people should do this, to help the core team test prereleases. I think we've run prereleases of every Clojure version in production -- and we've found bugs in a couple of the 1.12 alphas (one of which only showed up in production and only in one our of two dozen apps).

evocatus18:04:51

How to write a spec that will work with generators to check if a string follows a simple pattern like "ID12345"? I'm getting couldn't satisfy such-that predicate after 100 tries

seancorfield18:04:28

test-chuck has a regex generator that we use for stuff like this...

seancorfield18:04:18

com.gfredericks/test.chuck {:mvn/version "0.2.14"} https://github.com/gfredericks/test.chuck

๐Ÿ‘ 1
evocatus18:04:51

oh, thanks, haven't seen that

evocatus10:04:47

I found this one to work in my case (`#"ID\d{5}"`) while test.chuck couldn't do it https://github.com/miner/strgen