cannot close over mutable fields (in deftype)

Description

Simplest case:

1 2 3 4 5 6 7 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:

1 2 3 4 5 6 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)

Environment

None

Status

Assignee

Unassigned

Reporter

import

Labels

Approval

Vetted

Patch

None

Fix versions

Priority

Major
Configure