[squeak-dev] Re: [Pharo-project] Classes that implement unsafe #=

Chris Muller asqueaker at gmail.com
Thu May 31 03:38:17 UTC 2012


Good catch Mariano -- I have run your test on Squeak and fixed a
couple of instances there too.

On Wed, May 30, 2012 at 7:05 AM, Mariano Martinez Peck
<marianopeck at gmail.com> wrote:
> Hi guys. I found a problem while working with FuelPreview where we store
> objects of the graph in a Set. While doing a collect, there was an error
> because an implementation of #= was assuming that the argument was of a
> certain shape. Of course, that should answer false instead. So I wrote this
> test to see all existing wrong implementations:
>
> testAllClassesImplementSafeEqualsMethod
> "This tests that all classes in the system that implements #= do it in a way
> that they don't throw error when passing as an argument something different
> from expected. The correct behavior is that #= answers false."
>     | wrongClasses |
>     wrongClasses := IdentityDictionary  new.
>      ((SystemNavigation default allImplementorsOf: #=)
>             collect: [:each | each methodClass])
>             do: [:each |
>                 | instance |
>                 "Some classes like CompiledMethod override basicNew to throw
> an error.
>                 In any case, the comparison will be false, so no problem"
>                 [instance := each basicNew] on: Error do: [].
>                 [instance = Object new]
>                     on: Error
>                     do: [: err | wrongClasses at: each put: err ]].
>     self assert: wrongClasses isEmpty
>
>
> The result is: {Magnitude. WideCharacterSet. KMKeymap. MCMockDefinition.
> ScaledDecimal. MCSnapshot}
>
> So, my I think we should change #= in those classes by adding:
>
>     self == aKeymap
>         ifTrue: [ ^ true ].
>     self class = aKeymap class
>         ifFalse: [ ^ false ].
>
> at the beginning of the #=
>
> what do you think?  if agree, I open an issue.
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>


More information about the Squeak-dev mailing list