Fork me on GitHub
#clj-kondo
<
2021-11-30
>
tatut13:11:14

an idea, could linter warn about using case with Java enums like

(let [x java.util.concurrent.TimeUnit/SECONDS]
  (case x
    java.util.concurrent.TimeUnit/SECONDS "secs"
    java.util.concurrent.TimeUnit/MINUTES "mins"))
^ will cause "No matching clause" at runtime as case works with compile time literals... idk if this would be annoying when you actually do want to compare against symbols

borkdude13:11:08

how should clj-kondo know you're not actually matching against real symbols here?

tatut13:11:22

yeah, I see that's one issue

tatut13:11:57

I'd usually use keywords instead of symbols, but for me I'd say if the symbol matches an enum pattern some.Class/ENUM_VAL but that would perhaps be too opinionated as a general rule

NoahTheDuke14:11:13

would a type hint be usable here?

NoahTheDuke14:11:15

(let [^java.util.concurrent.TimeUnit x java.util.concurrent.TimeUnit/SECONDS] (case x …)) would then carry the “enum type” on x

NoahTheDuke14:11:43

it’s quite ugly lol but maybe clj-kondo could use it?