[CLJ-1023] non-tail-position try block breaks mutable fields in deftype Created: 08/Jul/12 Updated: 03/Dec/12 Resolved: 03/Dec/12 |
|
| Status: | Closed |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | Release 1.3, Release 1.4 |
| Fix Version/s: | None |
| Type: | Defect | Priority: | Minor |
| Reporter: | Stuart Sierra | Assignee: | Rich Hickey |
| Resolution: | Declined | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Description |
|
The :unsynchronized-mutable fields of a deftype cannot be set! inside a try block that is not in tail position of the method. See file *demonstration.clj* for an complete code example. |
| Comments |
| Comment by Rich Hickey [ 05/Sep/12 7:07 AM ] |
|
I looked at this. The problem is that non-tail try blocks turn into closures, and thus the field gets propagated as a constant. IOW this can't work: (deftype Foo4 [^:unsynchronized-mutable x]
MutableX
(set-x [this v]
((fn [] (set! x v)))
v))
I'm not going to re-evaluate the try/closure approach right now, so I recommend you make a helper method that just does the assignment and then call that in the bigger context, as a workaround. |
| Comment by Timothy Baldridge [ 03/Dec/12 10:55 AM ] |
|
Closing this as it requires more than a simple bug fix. If you feel that Rich's work-around is unsatisfactory please create a clojure-dev discussion about rewriting try-catch. |