Dmytro Shteflyuk created THRIFT-6111:
----------------------------------------
Summary: Ruby Struct equality should be symmetric across generated
classes
Key: THRIFT-6111
URL: https://issues.apache.org/jira/browse/THRIFT-6111
Project: Thrift
Issue Type: Bug
Components: Ruby - Library
Reporter: Dmytro Shteflyuk
Assignee: Dmytro Shteflyuk
h3. Problem
{{Thrift::Struct#==}} compares only the fields declared by the receiver. When
two different generated struct classes have overlapping field names, a value of
the narrower class can compare equal to a value of the wider class, while the
reverse comparison is false.
This violates the symmetry expected of Ruby equality: if {{a == b}} is true,
then {{b == a}} must also be true.
h3. Client impact
Applications can compare values from different generated Thrift types in
caching, deduplication, validation, or business logic. The current result
depends on operand order, so equivalent comparisons can make opposite
decisions. It also disagrees with the class-aware semantics already used by
{{eql?}} and {{hash}}.
h3. Reproduction
{code:ruby}
# A has: optional string shared
# B has: optional string shared, optional string extra
a = A.new(shared: "value")
b = B.new(shared: "value", extra: "different")
[a == b, b == a]
# current: [true, false]
# desired: [false, false]
{code}
h3. Expected behavior
{{==}} should compare generated Thrift struct values only when both operands
have the same generated class, then compare that class's declared fields. This
restores symmetric equality and aligns {{==}} with {{eql?}} and {{hash}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)