ruby-protobuf / protobuf

A pure ruby implementation of Google's Protocol Buffers
https://github.com/ruby-protobuf
MIT License
462 stars 101 forks source link

Fix enum hash equality #390

Closed liveh2o closed 5 years ago

liveh2o commented 5 years ago

Protobuf::Enum delegates methods to Fixnum, which has a custom hash equality method (eql?). This causes enum values to be equivalent when using ==, ===, equals?, but not eql?**:

2.3.7 :002 > Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO)
 => false

However, they are equilvalent to their tag value:

2.3.7 :002 > Test::EnumTestType::ZERO.eql?(::Test::EnumTestType::ZERO.tag)
 => true

Use the hash equality implementation from Object#eql?, which is equivalent to == instead.

**The implementation changed in Ruby 2.5, so this only affects Ruby versions less than v2.5.

film42 commented 5 years ago

Released as 3.8.5.pre0 for testing purposes.

liveh2o commented 5 years ago

Released in v3.8.5.