Not sure if this is the newly enhanced type linter, but I'm now getting a Redundant int coercion: expression already has type int on
(defn foo [bar]
(when (integer? bar)
(case (int bar) ;; <<<< here
0 "Low"
1 "Medium"
2 "High"
nil)))
I don't think the coercion is needed here from a case perspective, but I find the lint message somewhat confusing, as bar could be Short, Byte, BigInteger etc. and still pass the integer? checkIf that's the case, then our integer? specs are wrong. Issue welcome
Preferably with a repro of runtime code going wrong when changing it
by that you mean something like "if I remove the coerce flagged redundant, the behavior of my system changes in a bad way"?
yes
Kinda like:
(let [x 5]
(when (integer? x)
(= Integer (type (int x)))))
; true
(let [x 5]
(when (integer? x)
(= Integer (type x))))
; false
?yeah but more realistic? :)
I might have a hard time coming up with something non-convoluted. There are only a few places in code I know that has a call to (int) and the reasons are always something to do with how data is modeled or strict type checks, so the cast is required.
However, I still do not agree with the linter message in this case, because (integer? x) doesn't mean x is an int
I agree. I guess we could ask a robot to come up with a realistic case but we have to change the spec anyway, I agree
clj-kondo --lint - <<< "(fn [x] (when (integer? x) (int x)))"
<stdin>:1:28: info: Redundant int coercion: expression already has type int
linting took 122ms, errors: 0, warnings: 0
clj-kondo --lint - <<< "(fn [x] (when (integer? x) (long x)))"
linting took 60ms, errors: 0, warnings: 0
not getting the same for longI'll put these into a ticket
thank you
What would be the best way to get warnings about redefinition of clojure spec keywords? Edge cases seem to be ::kw in two different namespaces being different keywords, and :some-alias/kw in two different namespaces being the same keyword.
Can a hook properly resolve a keyword's namespace?