aphyr / dom-top

Unorthodox control flow, for Clojurists with masochistic sensibilities.
Eclipse Public License 1.0
204 stars 8 forks source link

Nullpointer exception in particular configuration #6

Open jeroenvandijk opened 1 year ago

jeroenvandijk commented 1 year ago

I found a scenario where I'm getting a Nullpointer exception for a certain configuration.

The following works:

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}]
         [current-dep deps0
          k (:provides current-dep)]
         (recur (assoc deps k current-dep)))) ;=> {:a {:provides #{:a}}}

Adapting the above with one extra accumulator arg2 now throws.

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}
          arg2 {}]
         [current-dep deps0
          k (:provides current-dep)]
         (recur (assoc deps k current-dep) arg2))) ;=> throws NullPointerException

Adding a default value [] works around this issue:

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}
          arg2 {}]
         [current-dep deps0
          k (:provides current-dep [])]
         (recur (assoc deps k current-dep) arg2)))  ;=> [{:a {:provides #{:a}}} {}]