From 2e8abaeceb66fdac19da67efcb3746d7f025b51b Mon Sep 17 00:00:00 2001 From: amedinae <31489998+amedinae@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:08:42 +0100 Subject: [PATCH] UNT0039 - Ignore generic types --- .../RequireComponentTests.cs | 17 +++++++++++++++++ .../RequireComponent.cs | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/Microsoft.Unity.Analyzers.Tests/RequireComponentTests.cs b/src/Microsoft.Unity.Analyzers.Tests/RequireComponentTests.cs index 01598f86..0a6c4cec 100644 --- a/src/Microsoft.Unity.Analyzers.Tests/RequireComponentTests.cs +++ b/src/Microsoft.Unity.Analyzers.Tests/RequireComponentTests.cs @@ -310,4 +310,21 @@ void Start() await VerifyCSharpFixAsync(test, fixedTest); } + + [Fact] + public async Task GenericTypeParameter() + { + const string test = @" +using UnityEngine; + +public class PlayerScript : MonoBehaviour +{ + void Foo() + { + var bar = GetComponent(); + } +}"; + + await VerifyCSharpDiagnosticAsync(test); + } } diff --git a/src/Microsoft.Unity.Analyzers/RequireComponent.cs b/src/Microsoft.Unity.Analyzers/RequireComponent.cs index 9a6e2dcd..b9686a09 100644 --- a/src/Microsoft.Unity.Analyzers/RequireComponent.cs +++ b/src/Microsoft.Unity.Analyzers/RequireComponent.cs @@ -66,6 +66,9 @@ private static void AnalyzeInvocation(SyntaxNodeAnalysisContext context) return; var componentType = method.TypeArguments.First(); // Checked by IsGenericGetComponent + if (componentType.TypeKind == TypeKind.TypeParameter) + return; + if (IsTypeAlreadyRequired(containerType, componentType)) return;