Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enum hash equality #390

Merged
merged 1 commit into from
Nov 13, 2018
Merged

Fix enum hash equality #390

merged 1 commit into from
Nov 13, 2018

Conversation

liveh2o
Copy link
Contributor

@liveh2o liveh2o commented Nov 9, 2018

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.

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.
@liveh2o liveh2o force-pushed the ah/fix_enum_hash_equality branch from 27dae6d to da5b844 Compare November 9, 2018 21:40
@film42
Copy link
Member

film42 commented Nov 9, 2018

Released as 3.8.5.pre0 for testing purposes.

@liveh2o liveh2o mentioned this pull request Nov 10, 2018
@liveh2o liveh2o merged commit f736e2b into master Nov 13, 2018
@liveh2o liveh2o deleted the ah/fix_enum_hash_equality branch November 13, 2018 17:19
@liveh2o
Copy link
Contributor Author

liveh2o commented Nov 13, 2018

Released in v3.8.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants