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

cannot close over mutable fields (in deftype)

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: Backlog
    • Labels:
    • Approval:
      Vetted

      Description

      Simplest case:

      user=>
      (deftype Bench [#^{:unsynchronized-mutable true} val]
        Runnable
        (run [_]
          (fn [] (set! val 5))))
      
      java.lang.IllegalArgumentException: Cannot assign to non-mutable: val (NO_SOURCE_FILE:5)
      

      Functions should be able to mutate mutable fields in their surrounding deftype (just like inner classes do in Java).

      Filed as bug, because the loop special form expands into a fn form sometimes:

      user=>
      (deftype Bench [#^{:unsynchronized-mutable true} val]
        Runnable
        (run [_]
          (let [x (loop [] (set! val 5))])))
      java.lang.IllegalArgumentException: Cannot assign to non-mutable: val (NO_SOURCE_FILE:9)
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: