ClojureScript

Incorrect transients behavior (dissoc! deletes too much)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

The snippet below reproduces the problem

(defn bug [seq]
  (let [m (transient (zipmap seq (repeat 1)))]
    (loop [m m
           [x & rest] seq]
      (when x
        (if (contains? m x)
          (recur (dissoc! m x) rest)
          (throw (js/Error. "What's going on?")))))))

(bug [44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24]]

Activity

Hide
Eldar Gabdullin added a comment -

Ah, transient lookup is not supported in Clojure. Why it is allowed in ClojureScript, then?

Show
Eldar Gabdullin added a comment - Ah, transient lookup is not supported in Clojure. Why it is allowed in ClojureScript, then?
Hide
Nicola Mometto added a comment - - edited

The fact that contains? doesn't work in clojure is a bug, see http://dev.clojure.org/jira/browse/CLJ-700

Show
Nicola Mometto added a comment - - edited The fact that contains? doesn't work in clojure is a bug, see http://dev.clojure.org/jira/browse/CLJ-700
Hide
Eldar Gabdullin added a comment -

Right, already spotted that.

Show
Eldar Gabdullin added a comment - Right, already spotted that.
Hide
Michał Marczyk added a comment - - edited

Wow, this is a pretty serious bug – thanks!

It is caused by an incorrect iteration bound in pack-array-node. The attached patch fixes it.

Show
Michał Marczyk added a comment - - edited Wow, this is a pretty serious bug – thanks! It is caused by an incorrect iteration bound in pack-array-node. The attached patch fixes it.
Hide
Michał Marczyk added a comment -

Oops, forgot the test. Attaching the same fix + test case.

Show
Michał Marczyk added a comment - Oops, forgot the test. Attaching the same fix + test case.
Hide
Michał Marczyk added a comment -

A final tweak.

Show
Michał Marczyk added a comment - A final tweak.
Hide
Eldar Gabdullin added a comment -

Thank you.

Show
Eldar Gabdullin added a comment - Thank you.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: