[comp.lang.smalltalk] refersToLiteral: bug in Smalltalk-80 2.5 and 4.0

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

Here's a small fix to a couple of bugs in Smalltalk-80 2.5 and 4.0 (and pre-2.5 as well).  It has to do with Smalltalk's ability to find methods that refer to literals.  You notice the problem most often when you ask for senders of a method (like: "exitProject") and Smalltalk will find methods that use a symbol #exitProject but won't find methods that have the symbol in a literal array like #(#exitProject #openBrowser).

You probably notice this most when you ask for senders of a method that gets called from a PopUpMenu.  Smalltalk often won't find the method because it only used the symbol for the method name inside of an array literal.

Anyway, the proper fix is simple, Array should just implement a refersToLiteral: method for itself.

While solving that problem, I noticed that BlockClosure's refersToLiteral: method also had a problem in it.  It won't work if the literal your looking for is the BlockClosure itself.  I'll admit a very rare case, but not impossible.  Again the proper fix for this is simple as well.

Following are the two methods that will fix these two problems.  (Would someone from ParcPlace please send me a message when they read this just so I know that someone from there got this?)


!Array methodsFor: 'testing'!

refersToLiteral: anObject

"The receiver is a literal in compiled code.  Answer whether the receiver contains a reference to anObject or is a reference to anObject."

	self detect: [:each | each refersToLiteral: anObject] ifNone: [^super refersToLiteral: anObject].
	^true! !


!BlockClosure methodsFor: 'testing'!

refersToLiteral: anObject

"The receiver is a literal in compiled code.  Answer whether the receiver contains a reference to anObject or is a reference to anObject."

	^(super refersToLiteral: anObject) | (method refersToLiteral: anObject)! !