Fork me on GitHub
#clj-kondo
<
2024-08-05
>
delaguardo10:08:26

Hi! I got a strange-looking error for extend-protocol:

❯ echo '(defprotocol IByteArray (-to-bytes [this])) (extend-protocol IByteArray (Class/forName "[B") (-to-bytes [_]))' | clj-kondo --lint -
<stdin>:1:88: error: Function name must be simple symbol but got: "[B"
linting took 28ms, errors: 1, warnings: 0

borkdude10:08:44

This has come up several times here. Search for Class/forName. This behavior isn’t officially supported by Clojure

delaguardo10:08:54

got it. thanks!

borkdude11:08:43

btw, perhaps you can use one of the new clojure 1.12 features here if you're willing to give 1.12 a try

borkdude11:08:16

user=> (= byte/1 (Class/forName "[B"))
true

delaguardo11:08:44

thanks, but I have to wait for the release 🙂 looks like for now the only option is to ignore entire form

borkdude11:08:45

I don't think that's supported yet by clj-kondo, darn ;)

borkdude11:08:53

yeah probably

borkdude11:08:04

the recommended approach is to use extend directly

borkdude11:08:18

as (Class/forName ..) isn't officially supported by Clojure in defprotocol

borkdude11:08:30

it just happens to work by accident. if you have multiple of those, it will fail

delaguardo11:08:36

right, it should work as well. I'll try this

seancorfield16:08:03

1.12 is already an RC! We're using Beta 1 and Beta 2 in production already.

borkdude16:08:38

yes, but unfortunately clj-kondo still doesn't support byte/1 as opposed to byte* which was an old thing

borkdude16:08:52

I bumped that issue to high priority now, should be in the next release

1
seancorfield16:08:17

I get the impression that only a handful of companies really help test the Clojure prerelease builds 😞

borkdude16:08:57

yeah, the real tests begin with an official release, I even notice that with my own projects ;)