[ 
https://issues.apache.org/jira/browse/THRIFT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657625#action_12657625
 ] 

Kevin Clark commented on THRIFT-231:
------------------------------------

>From the rdoc on Object#eql? and friends:

     Equality---At the +Object+ level, +==+ returns +true+ only if _obj_
     and _other_ are the same object. Typically, this method is
     overridden in descendent classes to provide class-specific meaning.

     [snip]

     The +eql?+ method returns +true+ if _obj_ and _anObject_ have the
     same value. Used by +Hash+ to test members for equality. For
     objects of class +Object+, +eql?+ is synonymous with +==+.
     Subclasses normally continue this tradition, but there are
     exceptions. +Numeric+ types, for example, perform type conversion
     across +==+, but not across +eql?

Thrift structs can't be equal unless they're of the same class. Seems odd to 
take the check out.

instance_variable_get will *almost* definitely return nil for fields they don't 
have in common... but how about something like:

class Foo
  def initialize(msg)
    @message = msg
  end
end

If Foo and a thrift exception like this exist:

exception Xception {
  1: string message,
}

Equality will work. Which, though unlikely, isn't unheard of.

> Ruby generated structs lack a hash method, and thus cannot be used as map 
> keys or set members
> ---------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-231
>                 URL: https://issues.apache.org/jira/browse/THRIFT-231
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Ruby), Library (Ruby)
>            Reporter: Bryan Duxbury
>            Assignee: Bryan Duxbury
>         Attachments: thrift-231.patch
>
>
> Since generated structs don't define a hash method in Ruby, it defaults to a 
> unique number every time. This means that even if two objects have equal 
> values, they will not have equal hashcodes. As a result, if you try to create 
> a set of these structs and subsequently attempt to test membership on an 
> equal struct, it'll always return false. The same problem prevents structs 
> from being used as map keys.
> At the very least, we should define a hash method that always returns 0 and 
> leave it up to the chaining to resolve the problem. A slightly more 
> appropriate move would be to have the hashcode of a struct be the composition 
> of its member values.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to