Skip to content

Fixes AD0001 in UNT0038#472

Merged
sailro merged 1 commit into
mainfrom
fix-ad0001-unt0038
Jun 2, 2026
Merged

Fixes AD0001 in UNT0038#472
sailro merged 1 commit into
mainfrom
fix-ad0001-unt0038

Conversation

@sailro

@sailro sailro commented Jun 2, 2026

Copy link
Copy Markdown
Member

Fixes #471

Checklist

  • I have read the Contribution Guide ;
  • There is an approved issue describing the change when contributing a new analyzer or suppressor ;
  • I have added tests that prove my fix is effective or that my feature works ;
  • I have added necessary documentation (if appropriate) ;

Short description of what this resolves:

Replaced unsafe construct with a proper check.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes AD0001 thrown by UNT0038 (CacheYieldInstructionAnalyzer) when a yielded object creation has more than one literal argument. The original code used SingleOrDefault which throws when multiple matching elements exist; the fix restricts analysis to object creations with exactly one argument that is a literal.

Changes:

  • Replace SingleOrDefault lookup with explicit "single argument that is a literal" check.
  • Add a regression test for yielded constructions with multiple literal arguments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.Unity.Analyzers/CacheYieldInstructionAnalyzer.cs Replaces unsafe SingleOrDefault predicate with a Count==1 + literal check.
src/Microsoft.Unity.Analyzers.Tests/CacheYieldInstructionAnalyzerTests.cs Adds regression test reproducing the AD0001 scenario from issue #471.

@sailro sailro merged commit c602b83 into main Jun 2, 2026
7 checks passed
@sailro sailro deleted the fix-ad0001-unt0038 branch June 2, 2026 17:07
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.

Analyzer UNT0038 throws AD0001 caused by exception whe yielded instance has >1 parameters

3 participants