Uploaded image for project: 'Clojure'
  1. CLJ-1075

deftype: compiler error on set! for mutable field

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects versions: Release 1.4
    • Fix versions: 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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: