[squeak-dev] #adoptInstance: vs. Morph -> BorderedMorph
leves at caesar.elte.hu
Thu Nov 21 10:07:59 UTC 2019
On Thu, 21 Nov 2019, Marcel Taeumel wrote:
> Hi, all.
> Why isn't the following code working?
> BorderedMorph adoptInstance: Morph new.
> In theory, I would expect all additional instance variables (borderWidth and borderColor) to be "nil".
BorderedMorph doesn't have the same format as Morph: it has two more
The method comment says:
"Change the class of the argument anInstance into the receiver, provided
that the format of the receiver matches the format of the argument's class."
So extra slots are not tolerated. I think the primitive simply changes
the class field of the object, so their formats must match to avoid VM
Perhaps you want to do is something like this instead:
changeClass := [ :instance :newClass |
| newInstance |
newInstance := newClass basicNew.
newInstance copyFrom: instance.
instance becomeForward: newInstance.
changeClass value: Morph new value: BorderedMorph
> The scenario is just workspace scripting. Trying something out. Setting up a scene, evaluating some code. Iterating quickly.
More information about the Squeak-dev