Welcome! Please see the About page for a little more info on how this works.

0 votes
in Compiler by

Reproducible Code: https://gist.github.com/patrickgombert/1bcb8a051aeb3e82d855

When using a volatile-mutable field in deftype, compilation fails if the field is set! in a method call that uses both try..finally and returns itself from the method call. Leaving out either the try..finally or returning itself from the method causes compilation to succeed.

Expected behavior: set! should set the volatile-mutable variable and compilation should succeed.

2 Answers

0 votes
by

Comment made by: hiredman

this must be the same issue as CLJ-1422 and CLJ-701, it has nothing to do with returning this, but with the try being in a tail position or not. if the try is not in a tail position the compiler hoists it out in to a thunk. effectively the code is

(deftype SomeType [^:volatile-mutable foo] SomeProtocol (someFn [_] ((fn [] (try (set! foo 1))))))

which the compiler also rejects, because it doesn't let you mutate fields from functions that are not the immediate protocol functions

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1708 (reported by alex+import)
...