Clojure

set! of a deftype field using field-access syntax causes ClassCastException

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.7
  • Fix Version/s: None
  • Component/s: None
  • Patch:
    Code and Test

Description

Clojure 1.6.0-master-SNAPSHOT

user=> (defprotocol p (f [_]))
p
user=> (deftype t [^:unsynchronized-mutable x] p (f [_] (set! (.x _) 1)))
user.t
user=> (f (t. 1))
ClassCastException user.t cannot be cast to compile__stub.user.t user.t (NO_SOURCE_FILE:1

After patch:
Clojure 1.6.0-master-SNAPSHOT
user=> (defprotocol p (f [_]))
p
user=> (deftype t [^:unsynchronized-mutable x] p (f [_] (set! (.x _) 1)))
user.t
user=> (f (t. 1))
1

Activity

Nicola Mometto made changes -
Field Original Value New Value
Attachment 0001-fix-CLJ-1226.patch [ 12046 ]
Nicola Mometto made changes -
Patch Code [ 10001 ]
Hide
Nicola Mometto added a comment - - edited

This patch offers a better workaround for CLJ-1075, making it possible to write
(deftype foo [^:unsynchronized-mutable x] MutableX (set-x [this v] (try (set! (.x this) v)) v))

Show
Nicola Mometto added a comment - - edited This patch offers a better workaround for CLJ-1075, making it possible to write (deftype foo [^:unsynchronized-mutable x] MutableX (set-x [this v] (try (set! (.x this) v)) v))
Alex Miller made changes -
Labels deftype
Nicola Mometto made changes -
Priority Minor [ 4 ] Major [ 3 ]
Affects Version/s Release 1.7 [ 10250 ]
Labels deftype compiler deftype interop
Nicola Mometto made changes -
Attachment 0001-fix-CLJ-1226.patch [ 12046 ]
Nicola Mometto made changes -
Nicola Mometto made changes -
Patch Code [ 10001 ] Code and Test [ 10002 ]
Summary set! of InstanceFieldExpr results in wrong type emission set! of a deftype field using field-access syntax causes ClassCastException

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: