Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-231

Ruby generated structs lack a hash method, and thus cannot be used as map keys or set members

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • Patch Available

    Description

      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.

      Attachments

        1. thrift-231.patch
          0.8 kB
          Bryan Duxbury
        2. thrift231.patch
          0.6 kB
          Dan Kinder

        Activity

          People

            bryanduxbury Bryan Duxbury
            bryanduxbury Bryan Duxbury
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: