clojure-dev 2024-11-27

In light of https://github.com/clojure/clojure/blob/13a2f67b91ab81cd109ea3152fce1ae76d212453/changes.md?plain=1#L103 I was wondering if it is possible to get the compiler to warn. I was going to write a JIRA, thinking that perhaps something could be added around here https://github.com/clojure/clojure/blob/13a2f67b91ab81cd109ea3152fce1ae76d212453/src/jvm/clojure/lang/Compiler.java#L4366 if, say *warn-on-static-field-invoke* is set or some such, but I started to wonder if that is well-defined. (Maybe at that point, it is known that the field cannot be invoked, or maybe it is more complicated.)

Alex Miller (Clojure team) 2024-11-27T20:49:06.144549Z

we pondered that long and hard and decided that it was too widespread right now to warn

Alex Miller (Clojure team) 2024-11-27T20:49:27.837139Z

clj-kondo has a linter for it so people are in many contexts now being warned

Alex Miller (Clojure team) 2024-11-27T20:50:03.739839Z

the next step may be to create a warning and then eventually an error or some controllable version of either

Right. It appears the clj-kondo linter only catches invocations of, say, enums defined in the Java core libraries, but not custom enums. It does indeed seem to be so prevalent, an approach like *warn-on-reflection*, where you opt into it, might be warranted

Cursive also warns about this now too, and will catch all cases (and offer to unwrap them). It does have a bug I need to fix where it will warn in cases where there is a field and also a static method name, but that should be fixed shortly.

I had a metric ton of cases in the Cursive codebase, so I can imagine it's pretty widespread.

👍 1

I found it easy to find cases by putting a breakpoint in Compiler.java (and then Cursive makes it trivial to fix them)

I was surprised at how many instances of this were in our code at work, once clj-kondo started warning about it!

@seancorfield if you’ve tried to eliminate all of them might be interesting to put a breakpoint in Conpiler.java and see if you find even more

That's too much effort 😄

Between you and I, this is analogous to incorrect grammar everyone ignores.

> it was too widespread right now to warn In order not to break builds/workflows, I'm assuming? Otherwise I'd consider widespread misuse a rather strong reason to do warn.

Alex Miller (Clojure team) 2024-11-28T13:28:11.263749Z

It would have been a deterrent to adoption