https://forum.world.st/Copying-classes-breaking-contract-or-not-tp4628606p4629964.html
It depends of the usage of copy...
className put: theClassCopy...
additional operation required.
> yes, this looks like a bug.
> But i would recompile all methods of copied class, so all these
> nuances is handled.
>
> On 12 May 2012 14:04, Mariano Martinez Peck <
[hidden email]> wrote:
>>
>>
>> On Sat, May 12, 2012 at 12:41 PM, Stéphane Ducasse
>> <
[hidden email]> wrote:
>>>
>>>
>>> On May 12, 2012, at 12:05 PM, Mariano Martinez Peck wrote:
>>>
>>> > Hi guys. The last literal of a instance-side compiled method always
>>> > points to the SAME (#==) association of the class in Smalltalk global.
>>> > The literals of a compiled method that refer to class variables refer to
>>> > the same association (#==) of the classPool of its class:
>>> >
>>> > self assert: ((GRPlatform class >> #current) literalAt: 1) ==
>>> > (GRPlatform classPool associationAt: #Current). -> true
>>> >
>>> > However, if I do a copy of the class:
>>> >
>>> > | copy |
>>> > copy := GRPlatform copy.
>>> > self assert: ((copy class >> #current) literalAt: 1) == (copy classPool
>>> > associationAt: #Current).
>>> >
>>> > this is not true anymore. Of course, you can see this because of the
>>> > Class >> #copy implementation:
>>> >
>>> > So my question is....is #copy breaking the contract (and therefore it
>>> > has to be fixed) or this is not mandatory for the system (as it is with the
>>> > last literal pointing to classes)?
>>>
>>> since namespace binding are shared between method literal and namespace, I
>>> think that this is a bug.
>>>
>>
>> I did this workaround
>>
>> Class >> rebindClassVariablesInMethods
>>
>> self class methodDict valuesDo: [ :aCompiledMethod |
>> 1 to: aCompiledMethod numLiterals-2 do: [ :index |
>> | literal |
>> literal := aCompiledMethod literalAt: index.
>> literal isVariableBinding ifTrue: [
>> (self innerBindingOf: literal key) ifNotNil: [:aBinding |
>> aCompiledMethod literalAt: index put: aBinding
>> ]
>> ]
>> ]
>> ]
>>
>>>
>>> Stef
>>> >
>>> > Thanks,
>>> >
>>> > --
>>> > Mariano
>>> >
http://marianopeck.wordpress.com>>> >
>>>
>>>
>>
>>
>>
>> --
>> Mariano
>>
http://marianopeck.wordpress.com>>
>
>
>
> --
> Best regards,
> Igor Stasenko.
>