Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in ClojureScript by

The inc function below will never receive a nil, but falsely warns that it might:

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

1 Answer

0 votes
ago by

The problem is the when. The inference mechanism isn't strong enough to narrow the return type (number|nil) if the type of the argument is known.

...