[BUG] Interval Copy
Andrew P. Black
black at cse.ogi.edu
Wed Mar 1 21:09:50 UTC 2000
I was a bit disconcerted to find that
(1 to: 10) copy
answers an array, not an Interval.
Interestingly, the Interval copy method says:
copy
"Return a copy of me. Override the superclass because my species is
Array and copy, as inherited from SequenceableCollection, uses
copyFrom:to:, which creates a new object of my species."
^self shallowCopy
Unfortunately, the comment is wrong -- perhaps it was right at some
time in the past, but at present (2.7) it is shallowCopy that is
overridden in SequencableCollection to use copyFrom:to:. So this copy
method does not help.
In fact, it just repeats what is already inherited from Object, so it
may as well be removed, along with the confusing comment.
The fix is to define shallowCopy in class Interval. But the only way
that I can think of to get the version in class Object, is to write
shallowCopy
^ self perform: #shallowCopy withArguments: #() inSuperclass: Object.
This is pretty ugly, but does the right thing, even if it does it
slowly. Is there a better suggestion from the list?
Andrew
More information about the Squeak-dev
mailing list
|