Skip to content

[System.Text.Json] Use root-level patterns for generated unions - #133017

Merged
eiriktsarpalis merged 2 commits into
mainfrom
eiriktsarpalis-stj-union-patterns
Sep 2, 2026
Merged

[System.Text.Json] Use root-level patterns for generated unions#133017
eiriktsarpalis merged 2 commits into
mainfrom
eiriktsarpalis-stj-union-patterns

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

Uses root-level type patterns for source-generated union deconstructors. Candidate for .NET 11 backport.

Note

This pull request was created with GitHub Copilot.

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

Copilot-Session: ea5cac06-c689-4f93-86c4-6a4f9cc9e60b
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.Emitter to emit root-level case patterns for UnionDeconstructor switch arms.
  • Update source-generator output baselines for recursive and subclass-case union scenarios across netcoreapp and net462.
  • 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

Comment thread src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ea5cac06-c689-4f93-86c4-6a4f9cc9e60b
Copilot AI review requested due to automatic review settings September 1, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@eiriktsarpalis
eiriktsarpalis enabled auto-merge (squash) September 2, 2026 11:00
@eiriktsarpalis

Copy link
Copy Markdown
Member Author

/ba-g test failures are unrelated to STJ

@eiriktsarpalis
eiriktsarpalis merged commit 696fda8 into main Sep 2, 2026
79 of 81 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the eiriktsarpalis-stj-union-patterns branch September 2, 2026 11:01
@eiriktsarpalis

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants