Repository navigation
Let a record declare its own equality in C# and Rust - #313
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014YYYK5TCGFXNo5ofZckGoo
|
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.



Requested by Matt · project thread
Fixes #301.
Before: a record that declared
operator ==oroperator !=did not compile in C# or in Rust. C# reported CS0111, because a record already synthesises both operators and the comparison-partner logic added whichever one was missing. Rust reported E0119, because the record derivedPartialEqbeside the declaredimpl PartialEq.After: both targets compile. In C#, a record's declared
==or!=is written down as inexpressible, since the record supplies both, and no partner is added for it. In Rust, a record that declares==leavesPartialEqout of its derive, so the declared impl is the only one. Records that declare no equality operator keep their current output.How:
CSharpGeneratorchecks whether an operator is one a record synthesises over its own type (RecordSynthesises) before writing it, andMissingComparisonPartnersskips those.RustGeneratordropsPartialEqfrom the derive list when the record declares==.RecordEqualityTestscompiles a record declaring==and one declaring only!=withdotnet buildandrustc, and pins the unchanged output for a plain record.Generated by Claude Code