Skip to content

Restore Color class semantics for derived type equality - #36076

Closed
jfversluis wants to merge 1 commit into
net11.0from
jfversluis-fix-color-derived-equality-net11
Closed

Restore Color class semantics for derived type equality#36076
jfversluis wants to merge 1 commit into
net11.0from
jfversluis-fix-color-derived-equality-net11

Conversation

@jfversluis

@jfversluis jfversluis commented Jun 23, 2026

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Fixes #36034.

This intentionally reverts the Color type-kind change from #33824 / commit 797df24 while keeping the useful [ImmutableObject(true)] metadata from that change.

The regression is caused by converting Color from a class to a record class: records add EqualityContract checks, so derived colors with the same ARGB value no longer compare equal. Keeping Color as a record and only changing equality would also leave existing class-based subclasses source-broken, because C# only allows records to inherit from records.

This restores Color to a normal class, removes the record-generated unshipped API entries, and adds regression coverage for base-vs-derived Color equality in both directions, EqualityComparer<Color>.Default, and matching hash codes.

cc @AdamEssenmacher, could you review this since you reported the issue?

Restore Color to class semantics while preserving immutability metadata, remove record-generated public API entries, and add regression coverage for derived Color equality.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36076

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36076"

@github-actions github-actions Bot added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label Jun 23, 2026
@jfversluis jfversluis changed the title Fix Color equality for derived types Restore Color class semantics for derived type equality Jun 23, 2026
@jfversluis
jfversluis marked this pull request as draft June 23, 2026 10:03
@jfversluis

Copy link
Copy Markdown
Member Author

Looking closer, I think this might be intentional and what the behavior should be

@AdamEssenmacher

Copy link
Copy Markdown
Contributor

@jfversluis I think you're probably right that the record/value-object direction is the better design.

The issue I filed exposed what I’d consider a Liskov Substitution problem: Color was open to inheritance, but record equality made that inheritance model no longer substitute cleanly.

My suggestions:

  1. Keep the record/value-object direction, but make Color sealed so inheritance is no longer part of the contract.
  2. Call out the behavior change in release notes, particularly that that == / != are now value-based for the Color type.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants