strange class creation behavior - compiler bug?

Bob Arning arning at charm.net
Tue Aug 27 13:49:30 UTC 2002


On Tue, 27 Aug 2002 09:39:40 -0400 "Larry White" <ljw1001 at hotmail.com> wrote:
>When I tried to instantiate using 'x := MyBuilding new: 'house', the system created a class called 'house' with the class name as the string rather than a usual symbol.Ê All attempts since that time to instantiate MyBuilding result in its initialize method being sent to the class 'house' rather than an instance of My Building.Ê The code for new: is simply 
>
>new: aString
>
>Ê ^ super new: aString initialize.

Larry,

If you want #initialize sent the the instance of MyBuilding in this example, you need to write

	^ (super new: aString) initialize

since the unary message #initialize has precedence over the keyword message #new: and would be sent first without the added parentheses.

BTW, I don't think the system created a class called 'house'. What you saw was an instance of String ('house') getting a message (#initialize) that it did not understand.

Cheers,
Bob



More information about the Squeak-dev mailing list