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

Fixed message equality in cases where the message type is different. #8434

Merged
merged 2 commits into from Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions ruby/ext/google/protobuf_c/message.c
Expand Up @@ -697,16 +697,13 @@ bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m) {
* field is of a primitive type).
*/
static VALUE Message_eq(VALUE _self, VALUE _other) {
if (TYPE(_self) != TYPE(_other)) {
return Qfalse;
}
if (CLASS_OF(_self) != CLASS_OF(_other)) return Qfalse;

Message* self = ruby_to_Message(_self);
Message* other = ruby_to_Message(_other);
assert(self->msgdef == other->msgdef);

return Message_Equal(self->msg, other->msg, self->msgdef)
? Qtrue
: Qfalse;
return Message_Equal(self->msg, other->msg, self->msgdef) ? Qtrue : Qfalse;
}

uint64_t Message_Hash(const upb_msg* msg, const upb_msgdef* m, uint64_t seed) {
Expand Down
3 changes: 2 additions & 1 deletion ruby/tests/common_tests.rb
Expand Up @@ -687,12 +687,13 @@ def test_deep_copy
assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
end

def test_eq
def test_message_eq
m = proto_module::TestMessage.new(:optional_int32 => 42,
:repeated_int32 => [1, 2, 3])
m2 = proto_module::TestMessage.new(:optional_int32 => 43,
:repeated_int32 => [1, 2, 3])
assert m != m2
assert_not_equal proto_module::TestMessage.new, proto_module::TestMessage2.new
haberman marked this conversation as resolved.
Show resolved Hide resolved
end

def test_enum_lookup
Expand Down