This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-09
Channels
- # adventofcode (95)
- # announcements (22)
- # aws (2)
- # babashka (14)
- # beginners (133)
- # bristol-clojurians (2)
- # calva (43)
- # cider (11)
- # clj-kondo (82)
- # cljsrn (20)
- # clojure (100)
- # clojure-europe (12)
- # clojure-italy (9)
- # clojure-nl (7)
- # clojure-poland (1)
- # clojure-spec (4)
- # clojure-uk (105)
- # clojurescript (42)
- # cryogen (1)
- # cursive (6)
- # data-science (1)
- # datomic (5)
- # euroclojure (2)
- # figwheel (4)
- # fulcro (4)
- # garden (1)
- # graphql (3)
- # hoplon (4)
- # jobs (1)
- # joker (3)
- # luminus (4)
- # malli (15)
- # off-topic (129)
- # pathom (10)
- # re-frame (43)
- # reagent (7)
- # reitit (3)
- # shadow-cljs (31)
- # vim (6)
- # yada (39)
hohum, thinking out loud, would it be possible to have a linter that warns about unregistered multimethod implementations..
Since now, there might be a case where a required namespace is marked as unused, but is required because a multimethod is registered
@viesti In that case you should just not use an alias for the namespace and then clj-kondo will ignore it
I've been playing around a bit with clj-kondo's type checker and found a few 'bugs' I wasn't sure were intentional
peek
and pop
are specced as taking vectors only whereas they actually take lists just fine
there are also lots of predicate any->boolean
core functions that aren't specced yet, is it just incomplete or are there some performance costs to having a larger database?
Is it right to say that nil
is always Associative? I can't think of a core function on maps that doesn't accept nils.
right now there seem to be a mix of :nilable/associative and :associative in the database
eg. I haven't tried it out yet, but given a function f
that was specced as {:ret nilable/number}
I was thinking it would be a great way of spotting potential places where null pointer exceptions could occur
if you want to have such checks, you will have to convince the type checker that (f)
will return a number, but often these checks rely on (if (number? (f)) (inc (f))
in dynamic code
it could be that CLJS already has this kind of type inference, but the type system in clj-kondo is pretty basic and does not attempt to resolve using occurrence typing
Got it, thanks for the explanations! Type theory and tooling is such a huge space to cover
the implementation is pretty straightforward: https://github.com/borkdude/clj-kondo/blob/master/src/clj_kondo/impl/types.clj#L42 any x that could be an y, will be considered as an y to satisfy the spec
the few functions that are specced with return types of :seqable-out like map
keep
always return lazy seqs, unless I'm mistaken
@qythium seqable-out doesn't include nil, whereas seqable does. so you should not rely on seqable-out being a nil, that's the point of it
I have some notes on it here:
** why seqable-out?
If we would make seqable functions to return a seqable, that would include
string and would turn this warning off:
$ clj -A:clj-kondo --lint - <<< '(defn foo [^String _x]) (foo (next [1 2 3]))'
<stdin>:1:30: warning: Expected: string or nil, received: seqable collection.
seqable? is a bit of an odd predicate, it includes nil and strings, that's why I have a seperate one
it's also about nil, because (next ..) could return nil (since nil is seqable) and then nilable X are satisfied as well, regardless of what X is
so eg. (peek (map ...))
should be a type error, whereas it currently thinks map could return a vector
yeah you should not rely on any of the seq functions to return a vector, so this is something we need to look at
please compare the output of .circleci/script/performance in your PR branch to the one on master for any regressions
automating that somehow would be nice, so a diff of that script output would show up in the PR, but that's another issue 😉
Is that supposed to be run locally? I tried executing .circleci/script/performance and it resulted in find: ./clj-kondo: No such file or directory
errors
if you push your branch to github and then go to http://circleci.com/gh/<your-user-name>/clj-kondo I think you should see something
❤️ @borkdude you just saved me hours of debugging
{:keys [state pc input] :as state}
~~~~~ unused binding state
I had one binding shadow another
@qythium I think I would prefer multiple smaller PRs instead of one big PR for the type annotations