EDIT: After posting the previous version of my question I discovered that the real problem is with nested functions.
If I have a closure within a deftype
I can not update any mutable fields from within that closure.
E.g. the following works:
(deftype Test [^:unsynchronized-mutable x]
TestInterface
(perform [this o] (set! x o)))
but this does not:
(deftype Test [^:unsynchronized-mutable x]
TestInterface
(perform [this o] (fn [] (set! x o)) nil)) ; throws a compiler error about assigning to non-mutable field
Is there any way to reach up and access the field? Doing (set! (.x this) o)
results in:
ClassCastException user.Test cannot be cast to compile__stub.user.Test user.Test/fn--152 (NO_SOURCE_FILE:3
When trying to run the code.
Code for TestInterface
for completeness:
(definterface TestInterface (perform [o]))