Repository navigation
Conversation
…hold Client: netstd The classes of the union members compared only the values in Equals, so values of different members could be equal, and GetHashCode() ignored the member. Equals now checks which member is set, and the hash code adds its field ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
THRIFT-6493
With the
unionoption, each member class of a generated union compared only the values inEquals, againstother.As_<member>. That property returns the default value when another member is set. SoU.x(0).Equals(U.y(0))was true, andU.x(0).Equals(U.s("text"))was true while the reverse was false.GetHashCode()ignored the member as well.Changes
t_netstd_generator.cc:Equalsof the member classes first checks which member is set, as the base class already does;GetHashCode()adds the member's field ID before the value, and the base class computes the same value. This applies to both the net and the netstandard code path.Thrift6493.thrift, added to the fourThrift.Compileprojects, andDataModel/UnionEquality.cs. The tests cover:HashSet;Compatibility
Union values of different members that hold equal values are no longer equal, and the hash codes of union values change.
Verification
Assert.IsFalse(new U.x(0).Equals(new U.y(0)))gets true;x(5)andy(5)both hash to 5;HashSetkeeps only 4 of 5 values.This is the union counterpart of THRIFT-5056 (#4104), which covers structs. The two PRs change different generator code and merge in either order.
🤖 Generated with Claude Code