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

Description

set! can be used to set a public field on an instance with (set! (.field inst) val). This does not work inside a protocol function defined on a deftype with a mutable field for an instance of that type itself.

Cause: The type assigned in the bytecode at this point is the compile_stub type, not the expected class type.

Approach: Use getType(targetClass) instead of Type.getType(targetClass)

Patch: 0001-CLJ-1226-fix-set-of-instance-field-expression-that-r-v2.patch
Screened by: Fogus

Environment

None

Activity

Show:
Nicola Mometto
June 27, 2013, 11:30 AM

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))

Nicola Mometto
March 25, 2015, 10:39 PM

Updated patch to apply to current master

Fogus
August 7, 2015, 9:10 PM

Straight-forward fix and test.

Rich Hickey
August 8, 2015, 4:05 PM

Screeners - please make sure the patch has an Approach section that explains how and why the patch will fix the problem. Symptom is X and now after patch behavior is Y is not good enough.

Completed

Assignee

Unassigned

Reporter

Nicola Mometto

Approval

Ok

Patch

Code and Test

Fix versions

Affects versions

Priority

Major