[squeak-dev] Object new becomeForward: #normal

Bert Freudenberg bert at freudenbergs.de
Tue Jul 18 14:24:39 UTC 2017


On Tue, Jul 18, 2017 at 1:33 PM, marcel.taeumel <Marcel.Taeumel at hpi.de>
wrote:

> Hi, there.
>
> Why are there guards to prevent forward-becoming to immediates (chars,
> ints)
> but not to symbols?
>
> This will break your image: "Object new becomeForward: #normal"
>
> ... because Cursor class MNU #normal ... :-) Either this is a bug or
> forward-becoming to symbols is not intended at all.
>

​The unexpected behavior is that #becomeForward: actually *modifies* the
target object, because it tries to preserve the identity hash by copying it
from the source to the target object. If you don't copy the hash it
actually works:

x := Object new.
x becomeForward: 42 copyHash: false.
x​
"=> 42"

y := Object new.
y becomeForward: #normal copyHash: false.
y
"=> #normal"

​Arguably "copyHash: false" is a safer default, but then again, it would
break identity-hashed collections that have the source object as key.

- Bert -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170718/9eb601a9/attachment.html>


More information about the Squeak-dev mailing list