Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;The following fails, it seems to be related to using try..finally and returning this
(defprotocol Foo
(-bar [this]))
(deftype Baz [^:volatile-mutable -oof]
Foo
(-bar [this]
(try
(set! -oof "something")
(finally "done"))
this))
;Exception in thread "main" java.lang.IllegalArgumentException: Cannot assign to non-mutable: _oof, compiling:(throwaway/core.clj:9:9)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.analyze(Compiler.java:6406)
; at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3665)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.analyze(Compiler.java:6406)
; at clojure.lang.Compiler$TryExpr$Parser.parse(Compiler.java:2162)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.analyze(Compiler.java:6406)
; at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
; at clojure.lang.Compiler$NewInstanceMethod.parse(Compiler.java:8008)
; at clojure.lang.Compiler$NewInstanceExpr.build(Compiler.java:7544)
; at clojure.lang.Compiler$NewInstanceExpr$DeftypeParser.parse(Compiler.java:7425)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.analyze(Compiler.java:6406)
; at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
; at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6100)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.analyze(Compiler.java:6406)
; at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
; at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
; at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
; at clojure.lang.Compiler.analyze(Compiler.java:6445)
; at clojure.lang.Compiler.eval(Compiler.java:6700)
; at clojure.lang.Compiler.load(Compiler.java:7130)
; at clojure.lang.RT.loadResourceScript(RT.java:370)
; at clojure.lang.RT.loadResourceScript(RT.java:361)
; at clojure.lang.RT.load(RT.java:440)
; at clojure.lang.RT.load(RT.java:411)
; at clojure.core$load$fn__5066.invoke(core.clj:5641)
; at clojure.core$load.doInvoke(core.clj:5640)
; at clojure.lang.RestFn.invoke(RestFn.java:408)
; at clojure.core$load_one.invoke(core.clj:5446)
; at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
; at clojure.core$load_lib.doInvoke(core.clj:5485)
; at clojure.lang.RestFn.applyTo(RestFn.java:142)
; at clojure.core$apply.invoke(core.clj:626)
; at clojure.core$load_libs.doInvoke(core.clj:5524)
; at clojure.lang.RestFn.applyTo(RestFn.java:137)
; at clojure.core$apply.invoke(core.clj:626)
; at clojure.core$require.doInvoke(core.clj:5607)
; at clojure.lang.RestFn.invoke(RestFn.java:421)
; at throwaway.core_test$eval182$loading__4958__auto____183.invoke(core_test.clj:1)
; at throwaway.core_test$eval182.invoke(core_test.clj:1)
; at clojure.lang.Compiler.eval(Compiler.java:6703)
; at clojure.lang.Compiler.eval(Compiler.java:6692)
; at clojure.lang.Compiler.load(Compiler.java:7130)
; at clojure.lang.RT.loadResourceScript(RT.java:370)
; at clojure.lang.RT.loadResourceScript(RT.java:361)
; at clojure.lang.RT.load(RT.java:440)
; at clojure.lang.RT.load(RT.java:411)
; at clojure.core$load$fn__5066.invoke(core.clj:5641)
; at clojure.core$load.doInvoke(core.clj:5640)
; at clojure.lang.RestFn.invoke(RestFn.java:408)
; at clojure.core$load_one.invoke(core.clj:5446)
; at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
; at clojure.core$load_lib.doInvoke(core.clj:5485)
; at clojure.lang.RestFn.applyTo(RestFn.java:142)
; at clojure.core$apply.invoke(core.clj:626)
; at clojure.core$load_libs.doInvoke(core.clj:5524)
; at clojure.lang.RestFn.applyTo(RestFn.java:137)
; at clojure.core$apply.invoke(core.clj:626)
; at clojure.core$require.doInvoke(core.clj:5607)
; at clojure.lang.RestFn.applyTo(RestFn.java:137)
; at clojure.core$apply.invoke(core.clj:626)
; at user$eval85.invoke(form-init9147790520409501019.clj:1)
; at clojure.lang.Compiler.eval(Compiler.java:6703)
; at clojure.lang.Compiler.eval(Compiler.java:6693)
; at clojure.lang.Compiler.load(Compiler.java:7130)
; at clojure.lang.Compiler.loadFile(Compiler.java:7086)
; at clojure.main$load_script.invoke(main.clj:274)
; at clojure.main$init_opt.invoke(main.clj:279)
; at clojure.main$initialize.invoke(main.clj:307)
; at clojure.main$null_opt.invoke(main.clj:342)
; at clojure.main$main.doInvoke(main.clj:420)
; at clojure.lang.RestFn.invoke(RestFn.java:421)
; at clojure.lang.Var.invoke(Var.java:383)
; at clojure.lang.AFn.applyToHelper(AFn.java:156)
; at clojure.lang.Var.applyTo(Var.java:700)
; at clojure.main.main(main.java:37)
;Caused by: java.lang.IllegalArgumentException: Cannot assign to non-mutable: _oof
; at clojure.lang.Compiler$ObjExpr.emitAssignLocal(Compiler.java:4840)
; at clojure.lang.Compiler$LocalBindingExpr.emitAssign(Compiler.java:5745)
; at clojure.lang.Compiler$AssignExpr.emit(Compiler.java:559)
; at clojure.lang.Compiler$BodyExpr.emit(Compiler.java:5826)
; at clojure.lang.Compiler$TryExpr.emit(Compiler.java:2089)
; at clojure.lang.Compiler$BodyExpr.emit(Compiler.java:5826)
; at clojure.lang.Compiler$FnMethod.doEmit(Compiler.java:5374)
; at clojure.lang.Compiler$FnMethod.emit(Compiler.java:5232)
; at clojure.lang.Compiler$FnExpr.emitMethods(Compiler.java:3771)
; at clojure.lang.Compiler$ObjExpr.compile(Compiler.java:4410)
; at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3904)
; at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
; ... 84 more
; The following variations which do not return this and do not use try..finally seem to succeed
(defprotocol Foo
(-bar [this]))
(deftype Baz [^:volatile-mutable -oof]
Foo
(-bar [this]
(try
(set! -oof "something")
(finally "done"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defprotocol Foo
(-bar [this]))
(deftype Baz [^:volatile-mutable -oof]
Foo
(-bar [this]
(set! -oof "something")
this))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.