unexpected type inference warning in Clojurescript 1.10.439

60 views
Skip to first unread message

Kim Kinnear

unread,
Jan 5, 2019, 2:02:02 PM1/5/19
to ClojureScript
I have code that compiles in Clojurescript as well as Clojure, and have noticed a new warning since moving to Clojurescript 1.10.439 from 1.10.339.  I expect that this is due to this enhancement to Clojurescript regarding "Function Return Type Inference".

This warning shows up when using figwheel and shadow-cljs.  Here is the shadow-cljs output since it shows the code nicely:


------ WARNING #1 --------------------------------------------------------------
 
File: zprint/focus.cljc:100:47
--------------------------------------------------------------------------------
 
97 |         #_(println "range-ssv: start:" start "nwpath:" nwpath)
 
98 |         start (skip-whitespace-ssv ssv start)
 
99 |         ssv-next (next-ssv ssv start)
 
100 |         end (if (and ssv-next (not= start 0)) (dec ssv-next) (dec (count ssv)))]
-----------------------------------------------------^--------------------------
 cljs
.core/-, all arguments must be numbers, got [#{nil clj-nil} number] instead
--------------------------------------------------------------------------------
 
101 |     #_(println "range-ssv:" [start end])
 
102 |     [start end]))
--------------------------------------------------------------------------------


It is true that the return from next-ssv can be nil, and so the value of of ssv-next can be nil.  It is also true that it would be an error to call dec with a nil value. But unless I'm really confused, that can never happen since the call to dec is protected by the if with ssv-next in the and function.

I can (and have) changed this code to make the warning go away, but are we expecting that Clojurescript should emit a warning in this situation?  

Thanks!
Reply all
Reply to author
Forward
0 new messages