[STJ] Fix formatting of flag enums when values are overlapping.#117730
[STJ] Fix formatting of flag enums when values are overlapping.#117730eiriktsarpalis merged 2 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
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.