Remove duplicate IsTypeReachableFromGeneratedCode in TestClassModelBuilder#9473
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR removes a duplicated accessibility check in the AOT reflection source generator by replacing TestClassModelBuilder.IsTypeReachableFromGeneratedCode with the shared SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode, aligning this generator with the existing pattern used by MSTestReflectionMetadataGenerator.
Changes:
- Deleted the local
IsTypeReachableFromGeneratedCodehelper fromTestClassModelBuilder. - Replaced the single call site with
SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode(current).
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/TestClassModelBuilder.cs | Replaces a duplicated reachability/accessibility helper with the shared SymbolAccessibilityHelper implementation. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Low
Evangelink
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
✅ 22/22 dimensions clean — no findings.
Semantic equivalence verified. The removed IsTypeReachableFromGeneratedCode and the replacement SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode produce identical results for all currently-defined Roslyn Accessibility values:
| Value | Old deny-list | New allow-list |
|---|---|---|
Public |
✅ (falls through) | ✅ (explicit continue) |
Internal |
✅ (falls through) | ✅ (explicit continue) |
ProtectedOrInternal |
✅ (falls through) | ✅ (explicit continue) |
NotApplicable |
✅ (falls through) | ✅ (explicit continue) |
Private |
❌ (explicit return false) |
❌ (default: return false) |
Protected |
❌ (explicit return false) |
❌ (default: return false) |
ProtectedAndInternal |
❌ (explicit return false) |
❌ (default: return false) |
The allow-list style in the shared helper is marginally more defensive — any hypothetical future Roslyn Accessibility value would be denied by default rather than accidentally allowed, which is the correct conservative behaviour for a generated-code reachability guard.
Additional observations:
- The
using MSTest.Analyzers.Shared;directive was already present on line 8, so no import was needed. SymbolAccessibilityHelper.IsAccessibleFromGeneratedCodeis already exercised byMSTestReflectionMetadataGeneratorandReflectionMetadataGenerator, giving indirect test coverage of the shared path.- No test changes are needed — this is a purely mechanical deduplication with no behavioral delta; the existing test suite validates the shared helper via the sibling generators.
- Scope is single-concern and tight: 1 addition, 24 deletions, one file.
TestClassModelBuilder.IsTypeReachableFromGeneratedCodewas a semantic duplicate ofSymbolAccessibilityHelper.IsAccessibleFromGeneratedCode, which is already linked into the same project and used by the siblingMSTestReflectionMetadataGenerator.Changes
IsTypeReachableFromGeneratedCodefromTestClassModelBuilder.csSymbolAccessibilityHelper.IsAccessibleFromGeneratedCodeNo project file changes needed —
SymbolAccessibilityHelper.csis already referenced via<Compile Include="..\Shared\SymbolAccessibilityHelper.cs" />andusing MSTest.Analyzers.Shared;was already present.The two implementations were semantically equivalent across all
Accessibilityvalues; they differed only in allow-list vs. deny-list style. The shared helper is the canonical version and explicitly handlesNotApplicable(which the duplicate only allowed implicitly).