[comp.lang.smalltalk] A bug in SequenceableCollection = in Smalltalk-80 v2.5

CWatts@BNR.CA (Carl Watts) (05/17/91)

Now, that I'm here I might as well post some other stuff...  There is a problem with SequenceableCollection = in Smalltalk-80 v2.5.  The problem has been fixed in version 4.0 but for those of us who still find v2.5 near and dear to our heart, I guess you should know about it.

The problem is that it does its size test before it does its species test.  This means the method will fail if you try and compare a SequencableCollection with an Object that isn't a Collection (or doesn't respondTo: #size).  Anyway, the method should read:

!SequenceableCollection methodsFor: 'comparing'!

= otherCollection 
	"Answer whether the species of the receiver is the same as otherCollection's species,
	and the receiver's size is the same as otherCollection's size, and each of the receiver's
	elements equal the corresponding element of otherCollection."

	| size index |
	self species == otherCollection species ifFalse: [^false].
	(size _ self size) = otherCollection size ifFalse: [^false].
	index _ 0.
	[(index _ index + 1) <= size]
		whileTrue: [(self at: index) = (otherCollection at: index) ifFalse: [^false]].
	^true! !