Bug: Use of == for arithmetic equality

Dan Ingalls Dan.Ingalls at Post.Harvard.edu
Mon Feb 13 17:37:42 UTC 2006


I've been playing around with a new VM (heh, heh) which, for a while, 
happened not to intern (ie force unique instances of) SmallIntegers. 
In this case the use of == to mean arithmetic equality will not work 
properly.  In my opinion, all such occurrences in the system should 
be eliminated ASAP;  == is not an arithmetic compare in any Smalltalk 
I know of.  While it may work with small constants, it is simply 
wrong, and an especially bad example for newbies to see.  Besides 
failing in certain interpreters, it will fail in Squeak itself if the 
integers are not small.

I regret that I don't have time to fix these right now.  However, if 
there is a well-intentioned soul out there, he or she will perhaps 
find the method below to be quite useful.  It found 165 methods in my 
system with this pattern.

Hope this helps.

	- Dan
-----------------------------------------------

<CompiledMethod>scanForEqSmallConstant
	"Answer whether the receiver contains the pattern 
<expression> == <constant>,
	where constant is -1, 0, 1, or 2..."

	| scanner |
	scanner _ InstructionStream on: self.
	^ scanner scanFor: [:instr | (instr between: 116 and: 119) 
and: [scanner followingByte = 198]]

"
SystemNavigation new browseAllSelect: [:m | m scanForEqSmallConstant]
"



More information about the Squeak-dev mailing list