Mantis - Squeak
Viewing Issue Advanced Details
7362 Morphic minor always 07-06-09 20:53 04-18-10 22:04
sig any  
nicolas cellier any  
normal any  
closed 3.10  
none trunk  
0007362: Text>>copyFrom:to: prevents using a subclasses
In one of my experiments, i tried to subclass a Text by own subclass,
and i found that when i trying to pass its instance to a Workspace,
the workspace morph instead of operating with my intance of Text
subclass, unexpectably uses the instance of Text , which seems
appeared out of nowhere.

The root of all evil is in Text>>copyFrom:to:

copyFrom: start to: stop
       "Answer a copied subrange of the receiver."

       | realStart realStop |
       stop > self size
               ifTrue: [realStop _ self size] "handle selection at end of string"
               ifFalse: [realStop _ stop].
       start < 1
               ifTrue: [realStart _ 1] "handle selection before start of string"
               ifFalse: [realStart _ start].
>>> ^Text
               string: (string copyFrom: realStart to: realStop)
               runs: (runs copyFrom: realStart to: realStop)

after replacing 'Text' with 'self class' , everything works perfectly.
Here the way to reproduce it & test code which should not fail:

| txtClass text |

txtClass := Text clone.
txtClass methodDict: MethodDictionary new; superclass: Text.

text := txtClass fromString: 'blahblah'.

self assert: ( text copyFrom: 1 to: text size) class == txtClass.

nicolas cellier   
10-19-09 10:33   
Fixed in [^]