is this a bug? I think the anonymous function inside some-> is throwing off the type inference, since inc can’t receive a nil here. I can hide the warning by tagging the form with ^number:
$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.12.134"}}}' -M -m cljs.main -re node
ClojureScript 1.12.134
cljs.user=> (some-> 1 (#(when (pos? %) %)) inc)
WARNING: cljs.core/+, all arguments must be numbers, got [#{nil clj-nil} number] instead at line 1 <cljs repl>
2
cljs.user=> (some-> 1 ^number (#(when (pos? %) %)) inc)
2Type inference in CLJS is relatively sparse. It's gets improved once in a while but it's not something one should rely upon IMO. If it warns you, it might or might not be worth fixing. If it doesn't warn you, you might still have some issues in your code that a more comprehensive type checking system would warn you about. But that's not to say that it's not useful, of course - it covers a lot, if not most, of common mistakes.
yeah, well it’s a false positive warning, so I’ll file a bug then
apologies, didn’t realize I should be reporting bugs to ask.clojure. not slack: https://ask.clojure.org/index.php/14870/false-positive-warning-cljs-core-all-arguments-must-numbers
It's not some->, it's that (when (pos? %) ...).
ClojureScript does not analyze values, so it doesn't know whether the value is positive there, so the result of that (when ...) is inherently either nil or a number.
I wonder why this doesn’t give the same warning then:
(some-> 1 (#(rand-nth [nil %])) inc)oh I guess rand-nth is not typed at all, whereas when is typed somehow
also I expected some-> to have some analysis to cut away the possible nil types since those aren’t passed along