[System.Text.Json] Use root-level patterns for generated unions - #133017
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea5cac06-c689-4f93-86c4-6a4f9cc9e60b
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the System.Text.Json source generator’s emitted union deconstructor switch to use root-level type patterns (instead of matching through the union’s Value property), and refreshes the associated source-generator baselines and test commentary to reflect the new output.
Changes:
- Update
JsonSourceGenerator.Emitterto emit root-level case patterns forUnionDeconstructorswitch arms. - Update source-generator output baselines for recursive and subclass-case union scenarios across
netcoreappandnet462. - Adjust unit-test comments to reflect the new “root-level pattern” approach.
File summaries
| File | Description |
|---|---|
| src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs | Changes union deconstructor codegen to use root-level type patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorOutputTests.cs | Updates commentary for union baseline verification cases. |
| src/libraries/System.Text.Json/tests/Common/UnionTests.cs | Updates explanatory comments around union pattern behavior expectations. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/SubclassCaseUnionType/netcoreapp/MyContext.Shape.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/SubclassCaseUnionType/net462/MyContext.Shape.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/RecursiveUnionType/netcoreapp/MyContext.Nat.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/RecursiveUnionType/net462/MyContext.Nat.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/RecursiveNullableUnionType/netcoreapp/MyContext.Nat.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
| src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/Baselines/RecursiveNullableUnionType/net462/MyContext.Nat.g.cs.txt | Baseline update reflecting new deconstructor switch patterns. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea5cac06-c689-4f93-86c4-6a4f9cc9e60b
tannergooding
approved these changes
Sep 2, 2026
eiriktsarpalis
enabled auto-merge (squash)
September 2, 2026 11:00
Member
Author
|
/ba-g test failures are unrelated to STJ |
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
4 tasks
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.
Uses root-level type patterns for source-generated union deconstructors. Candidate for .NET 11 backport.
Note
This pull request was created with GitHub Copilot.