Skip to content

Comments

UNT0039 - Ignore generic types#446

Merged
sailro merged 1 commit intomicrosoft:mainfrom
amedinae:unt0039-ignore-generics
Feb 14, 2026
Merged

UNT0039 - Ignore generic types#446
sailro merged 1 commit intomicrosoft:mainfrom
amedinae:unt0039-ignore-generics

Conversation

@amedinae
Copy link
Contributor

@amedinae amedinae commented Feb 11, 2026

Fixes #445

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:

This PR fixes a false positive in UNT0039 where the analyzer incorrectly flagged GetComponent() calls when T was a generic type parameter. Since C# attributes (like [RequireComponent]) cannot accept generic type parameters as arguments, adhering to the analyzer's suggestion was impossible in these cases.

Changes proposed in this pull request:

  • Updated RequireComponentAnalyzer.AnalyzeInvocation to check the TypeKind of the component type.
  • The analyzer now returns early (ignoring the diagnostic) if the component type is a TypeParameter, preventing false positives on generic methods.
  • Added a new test case GenericTypeParameter to RequireComponentTests.cs to verify that generic GetComponent calls are correctly ignored.

@amedinae amedinae requested a review from a team as a code owner February 11, 2026 23:16
@amedinae
Copy link
Contributor Author

@microsoft-github-policy-service agree

@sailro
Copy link
Member

sailro commented Feb 14, 2026

Thank you very much for this contribution !

@sailro sailro merged commit e34d438 into microsoft:main Feb 14, 2026
6 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.

Ignore UNT0039 on generics types

2 participants