On Fri, Mar 01, 2019 at 05:18:27PM +0100, Sven Van Caekenberghe wrote:
> 
> 
> > On 1 Mar 2019, at 17:08, Petr Fischer via Pharo-users 
> > <pharo-users@lists.pharo.org> wrote:
> > 
> > 
> > From: Petr Fischer <petr.fisc...@me.com>
> > Subject: Symbol equality method #= - weird condition in the Pharo sourcecode
> > Date: 1 March 2019 at 17:08:03 GMT+1
> > To: pharo-users@lists.pharo.org
> > 
> > 
> > Hello, this is Symbol equality method in Pharo:
> > 
> > 1: = aSymbol
> > 2:  "Compare the receiver and aSymbol." 
> > 3:  self == aSymbol ifTrue: [^ true].
> > 4:  self class == aSymbol class ifTrue: [^ false].
> > 5:  "Use String comparison otherwise"
> > 6:  ^ super = aSymbol
> > 
> > Look at line 4 - what does it mean? That's wrong, isn't it?
> > 
> > Typically, every symbol comparisons end up in line 3, but if you do some 
> > work with forward proxies for example, condition on line 3 is "false" and 
> > then weird things on line 4 happens.
> > 
> > If line 4 and further are correct, can someone explain a little?
> > 
> > Thanks! pf
> 
> Yes, that looks weird. Line 4 should probably be removed, unless I am missing 
> something.

It is wrong in a Spur image, because we now have subclasses of Symbol.
But removing line 4 is not the right solution. See Nicolas' implementation
in Squeak:

Symbol>>= aSymbol
        "Compare the receiver and aSymbol." 
        self == aSymbol ifTrue: [^ true].
        aSymbol isSymbol ifTrue: [^ false].
        "Use String comparison otherwise"
        ^ super = aSymbol

Dave

> 
> Symbols are by definition always #== so in that sense, #= should not even be 
> implemented (as #= on Object is defined as #==), but since its direct super 
> class String already overwrote #=, it has to follow.
> 
> The super call in line 6 is what allows Symbols and String to be compared.
> 
> I would say line 4 is a kind of sanity check, but probably not needed.
> 
> 

Reply via email to