Fork me on GitHub
#clj-kondo
<
2022-06-02
>
hiredman17:06:01

it seems like kond doesn't understand how recur works inside a deftype/defrecord inline protocol extension or interface implementation. when you recur in those you don't pass the this argument, which kondo flags as an error

hiredman17:06:50

I don't see any existing issues on github for this, but describing it in a search term is tricky

borkdude17:06:08

@U0NCTKEV8 Can you make an example of this?

dpsutton17:06:06

(defprotocol CountDown
  (count-down [_ n]))
(count-down
 (reify CountDown
   (count-down [_ n] (if (zero? n) :done (recur (dec n)))))
 5)

borkdude17:06:44

Hmm, this works:

(defprotocol IFoo (-foo [_]))
(defrecord Foo [] IFoo (-foo [x] (recur x)))

hiredman17:06:39

(deftype Foo [] java.lang.Runnable (run [this] (recur)))
gets flagged for example

hiredman17:06:05

user=> (defprotocol IFoo (-foo [_]))
(defrecord Foo [] IFoo (-foo [x] (recur x)))
IFoo
user=> Syntax error (IllegalArgumentException) compiling recur at (REPL:1:34).
Mismatched argument count to recur, expected: 0 args, got: 1
user=>
`

hiredman17:06:08

doesn't work

borkdude17:06:18

For now you can use #_:clj-kondo/ignore before the false positives to suppress it

borkdude17:06:58

So I think these are all related:

(defprotocol IFoo (-foo [_]))
(defrecord Foo [] IFoo (-foo [x] (recur)))
(deftype Foo [] java.lang.Runnable (run [this] (recur)))
(reify IFoo (-foo [_] (recur)))
The recur arity should be one less in protocol method implementations

👍 1
borkdude17:06:08

I'll make an issue for this

borkdude17:06:38

Thanks for reporting

hiredman17:06:38

thanks for creating the issue, I was flailing around in the template still

borkdude10:06:20

Fixed on master