Clojure

deftype: compiler error on set! for mutable field

Details

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

Description

The following code demonstrates the error in a minimal example:

(defprotocol IBlob (do-sth [this, x]))

(deftype Blob [^{:volatile-mutable true} a]
  IBlob
  (do-sth [this, x] 
    (try (/ 1 x) 
      (catch Throwable t 
        (set! a (inc a))))
        (inc x)))

(deftype Blob2 [^{:volatile-mutable true} a]
  IBlob
  (do-sth [this, x] 
    (try (/ 1 x) 
      (catch Throwable t 
        (set! a (inc a))))))

Compiling Blob results in the following exception:

CompilerException java.lang.IllegalArgumentException: Cannot assign to non-mutable: a

Compiling Blob2 works as expected.

Activity

Timothy Baldridge made changes -
Field Original Value New Value
Resolution Duplicate [ 3 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: