Skip to content

Remove duplicate IsTypeReachableFromGeneratedCode in TestClassModelBuilder#9473

Merged
Evangelink merged 2 commits into
mainfrom
copilot/duplicate-code-fix
Jun 28, 2026
Merged

Remove duplicate IsTypeReachableFromGeneratedCode in TestClassModelBuilder#9473
Evangelink merged 2 commits into
mainfrom
copilot/duplicate-code-fix

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

TestClassModelBuilder.IsTypeReachableFromGeneratedCode was a semantic duplicate of SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode, which is already linked into the same project and used by the sibling MSTestReflectionMetadataGenerator.

Changes

  • Deleted IsTypeReachableFromGeneratedCode from TestClassModelBuilder.cs
  • Replaced its single call site with SymbolAccessibilityHelper.IsAccessibleFromGeneratedCode

No project file changes needed — SymbolAccessibilityHelper.cs is already referenced via <Compile Include="..\Shared\SymbolAccessibilityHelper.cs" /> and using MSTest.Analyzers.Shared; was already present.

The two implementations were semantically equivalent across all Accessibility values; they differed only in allow-list vs. deny-list style. The shared helper is the canonical version and explicitly handles NotApplicable (which the duplicate only allowed implicitly).

Copilot AI self-assigned this Jun 27, 2026
Copilot AI review requested due to automatic review settings June 27, 2026 05:39
Copilot AI removed the request for review from Copilot June 27, 2026 05:39
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 27, 2026 05:45
Copilot AI changed the title [WIP] Fix duplicate code in TestClassModelBuilder Remove duplicate IsTypeReachableFromGeneratedCode in TestClassModelBuilder Jun 27, 2026
Copilot AI requested a review from Evangelink June 27, 2026 05:46
@Evangelink Evangelink marked this pull request as ready for review June 28, 2026 04:53
Copilot AI review requested due to automatic review settings June 28, 2026 04:53
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jun 28, 2026

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.

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 IsTypeReachableFromGeneratedCode helper from TestClassModelBuilder.
  • 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 Evangelink enabled auto-merge (squash) June 28, 2026 05:00

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.IsAccessibleFromGeneratedCode is already exercised by MSTestReflectionMetadataGenerator and ReflectionMetadataGenerator, 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.

@Evangelink Evangelink merged commit 5731c45 into main Jun 28, 2026
37 checks passed
@Evangelink Evangelink deleted the copilot/duplicate-code-fix branch June 28, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants