-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[STJ] Fix formatting of flag enums when values are overlapping. #117730
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
[STJ] Fix formatting of flag enums when values are overlapping. #117730
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the formatting of flag enums when values are overlapping by implementing a topological sort to ensure proper ordering of enum values during serialization. The issue occurs when flag enums have values that are supersets of other values (e.g., BITS01 = 3
which combines BIT0 = 1
and BIT1 = 2
).
Key Changes:
- Added topological sorting for flag enums to ensure superset values are processed before their constituent parts
- Implemented Kahn's algorithm to handle the ordering dependencies between overlapping enum values
- Added comprehensive tests to verify the fix works for different scenarios of overlapping flag enum values
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
EnumConverter.cs | Implements topological sorting logic using Kahn's algorithm for flag enums to ensure proper ordering of overlapping values |
EnumConverterTests.cs | Adds test cases for flag enums with overlapping bit values to verify serialization produces expected output |
...raries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
Outdated
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
Outdated
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
...raries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
Show resolved
Hide resolved
/ba-g test failures unrelated to change. |
/backport to release/9.0-staging |
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/16368520024 |
Fix #114770.