cljs-dev

borkdude 2024-08-21T15:27:07.431559Z

Not sure if I'm hitting a bug here or not. I'm getting a warning here for something that is supposed to be always a number and never nil:

WARNING: cljs.core/<=, all arguments must be numbers, got [number #{nil clj-nil}] instead at line 120 /Users/borkdude/dev/edamame/src/edamame/impl/parser.cljc
WARNING: cljs.core/<=, all arguments must be numbers, got [#{nil clj-nil} number] instead at line 120 /Users/borkdude/dev/edamame/src/edamame/impl/parser.cljc
but this local is bound in if-let so it's guaranteed to be never nil. I'll post the whole function in a thread for further inspection

dnolen 2024-08-22T18:01:08.828299Z

I think it's probably just another instance of the problem, this has been reported for some time, we have a special case for handling protocols, but I am thinking about a more general solution

borkdude 2024-08-21T15:27:22.838689Z

(defn parse-symbol
  "Parses a string into a vector of the namespace and symbol"
  [^String token]
  (when-not (or (= "" token)
                (.endsWith token ":")
                (.startsWith token "::"))
    (let [ns-idx (.indexOf token "/")]
      (if-let [^String ns (and (pos? ns-idx)
                               (subs token 0 ns-idx))]
        (let [ns-idx (inc ns-idx)]
          (when-not (== ns-idx (count token))
            (let [^String sym (subs token ns-idx)]
              (when (not (.endsWith ns ":"))
                (if-let [n (when (= 1 #?(:clj (.length sym)
                                        :cljs (.-length sym)))
                             (try #?(:clj (Integer/parseInt sym)
                                     :cljs (let [x (js/parseInt sym)]
                                             (when-not (NaN? x)
                                               x)))
                                  (catch Exception _ nil)))]
                  (when (<= 1 n 9)
                    [ns sym])
                  (when (and (not (utils/numeric? (nth sym 0)))
                             ;; can't reach here probably?
                             (not (= "" sym))
                             (or (= "/" sym )
                                 (== -1 (.indexOf sym "/"))))
                    [ns sym]))))))
        (when (or (= "/" token)
                  (== -1 (.indexOf token "/")))
          [nil token])))))

borkdude 2024-08-21T15:27:53.567329Z

The warning comes from

(when (<= 1 n 9)
  [ns sym])

p-himik 2024-08-21T15:31:12.867409Z

Perhaps this? https://clojure.atlassian.net/browse/CLJS-3414 Originally discussed in https://clojurians.slack.com/archives/C03S1L9DN/p1720080756766299

borkdude 2024-08-21T15:33:36.668089Z

Can't say for sure if this is the exact same case

borkdude 2024-08-21T15:37:48.426619Z

Slapping a ^js type hint on it helps