Skip to content

fix(analyzers): drop the nonexistent TryGetValue from E128221 - #169

Merged
e128 merged 1 commit into
mainfrom
fix/union-value-read-guidance
Nov 16, 2026
Merged

e128 merged 1 commit into
mainfrom
fix/union-value-read-guidance

Conversation

@e128

@e128 e128 commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Executive Summary

E128221 reported a Value read on a union and told the developer to rewrite it as a pattern or a TryGetValue call. The second option does not exist. A compiler-declared union exposes Value and case patterns only.

Probed on net11.0 at LangVersion latest and again at preview, with Roslyn 5.12.0: result.TryGetValue(out var value) fails with CS1061, and result.HasValue fails the same way. The rule message, the XML doc, the package README, and the lode rule detail now name the pattern only.

Code Changes

  • UnionValueReadAnalyzer: message and XML doc name a case pattern. No rule id, category, or severity change.
  • src/E128.Analyzers/README.md: E128221 prose and the After example use a pattern. The install version moves to 3.1.1.
  • AnalyzerReleases.Shipped.md: new Release 3.1.1 section carries the E128220 row from Unshipped plus a new E128221 row.
  • E128.Analyzers.csproj: version 3.1.0 to 3.1.1.
  • Directory.Packages.props: Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.CSharp.CodeStyle, and Microsoft.CodeAnalysis.CSharp.Workspaces move 5.9.0 to 5.12.0. Meziantou.Analyzer moves 3.0.326 to 3.0.341. PolySharp moves to 1.17.1.
  • lode/dotnet/analyzers/rule-details-union.md: records the probe result and the corrected rule text.
  • lode/dotnet/analyzers/authoring.md: probe timestamp refreshed after the suite passed on the new band.

The 5.12.0 band adds the C# 15 language version and union pattern plumbing. IDE diagnostic ids (132) and style options (126) are identical to 5.9.0, so no .editorconfig entry changes.

Tests and Tooling

  • scripts/check.sh --all: shell lint, format check, build, and full suite pass.
  • Full suite: 2992 total, 2990 passed, 0 failed, 2 skipped. The two skips predate this change.
  • Build: 0 warnings under AnalysisLevel latest-all and AnalysisMode All.
  • scripts/internal/analyzer-release-check.sh --json: clean.
  • scripts/readme-table-diff.sh --analyzer --json: no drift.

Not run: the reference app was not launched against the package. The union probe compiled inside E128.Reference.Core and the probe file was removed before commit.

Review Guide

Start at UnionValueReadAnalyzer.cs for the message and doc change. Then read the E128221 section of src/E128.Analyzers/README.md. The rest is version and release bookkeeping.

Rollback

Revert the commit. No public API, rule id, category, or severity changes. The version can drop back to 3.1.0 if 3.1.1 has not been published.

Links

🤖 Generated with Claude Code

E128221 told callers to read a union case through TryGetValue. Probed on
net11.0 at LangVersion latest and preview, and on Roslyn 5.12.0, a
compiler-declared union exposes no TryGetValue member and no HasValue
property. The message, the XML doc, and the README now name a case pattern
only. Bump E128.Analyzers to 3.1.1 and promote the changed rule rows.

Move Microsoft.CodeAnalysis.CSharp and the CodeStyle package to 5.12.0.
The band adds C# 15 and union pattern plumbing, with no new IDE rules or
style options. Meziantou.Analyzer moves to 3.0.341. Build reports no new
diagnostic.

Co-Authored-By: Claude
@e128
e128 merged commit 5c7789c into main Nov 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant