clj-kondo

Kirill Chernyshov 2024-08-05T10:44:26.384399Z

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

borkdude 2024-08-05T10:45:44.582469Z

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

Kirill Chernyshov 2024-08-05T10:46:54.842319Z

got it. thanks!

borkdude 2024-08-05T11:08:43.107349Z

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

borkdude 2024-08-05T11:13:16.957869Z

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

Kirill Chernyshov 2024-08-05T11:14:44.212779Z

thanks, but I have to wait for the release πŸ™‚ looks like for now the only option is to ignore entire form

borkdude 2024-08-05T11:14:45.985639Z

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

borkdude 2024-08-05T11:14:53.421579Z

yeah probably

borkdude 2024-08-05T11:15:04.932529Z

the recommended approach is to use extend directly

borkdude 2024-08-05T11:15:18.418959Z

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

borkdude 2024-08-05T11:15:30.462749Z

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

Kirill Chernyshov 2024-08-05T11:15:36.035959Z

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

seancorfield 2024-08-05T16:26:03.476179Z

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

borkdude 2024-08-05T16:29:38.367059Z

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

borkdude 2024-08-05T16:29:52.090829Z

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

πŸ‘πŸ» 1
seancorfield 2024-08-05T16:36:17.686579Z

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

borkdude 2024-08-05T16:36:57.659869Z

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

2024-09-01T15:23:13.603779Z

I wonder how to incentivize that better.