clojure-dev

mfikes 2024-11-27T20:39:55.385669Z

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

mfikes 2024-11-27T20:56:42.064239Z

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

cfleming 2024-11-27T21:12:23.664219Z

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.

cfleming 2024-11-27T21:12:53.504219Z

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

👍 1
mfikes 2024-11-27T21:14:41.677129Z

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

seancorfield 2024-11-27T21:44:51.481879Z

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

mfikes 2024-11-27T21:46:56.012769Z

@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

seancorfield 2024-11-27T21:53:09.123239Z

That's too much effort 😄

mfikes 2024-11-27T21:58:03.770589Z

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

imre 2024-11-28T10:17:55.500699Z

> 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

imre 2024-11-28T15:03:40.279989Z

understandable