From 36b29fe81b28048040f84931fde420c818b03f41 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Apr 2026 19:26:57 +0000 Subject: [PATCH 1/3] Initial plan From c324122e5fb1f03982b0e337371fc6b8978fde7a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Apr 2026 19:38:16 +0000 Subject: [PATCH 2/3] Fix MA0182 for types used only in is type checks Agent-Logs-Url: https://github.com/meziantou/Meziantou.Analyzer/sessions/15397ed1-8740-4288-9c12-fadc3d3c4ea4 Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- .../Rules/AvoidUnusedInternalTypesAnalyzer.cs | 10 +++++++ .../AvoidUnusedInternalTypesAnalyzerTests.cs | 27 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Meziantou.Analyzer/Rules/AvoidUnusedInternalTypesAnalyzer.cs b/src/Meziantou.Analyzer/Rules/AvoidUnusedInternalTypesAnalyzer.cs index 2ad4660a4..6c593bdee 100644 --- a/src/Meziantou.Analyzer/Rules/AvoidUnusedInternalTypesAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/AvoidUnusedInternalTypesAnalyzer.cs @@ -41,6 +41,7 @@ public override void Initialize(AnalysisContext context) ctx.RegisterOperationAction(analyzerContext.AnalyzeMemberReference, OperationKind.PropertyReference, OperationKind.FieldReference, OperationKind.MethodReference, OperationKind.EventReference); ctx.RegisterOperationAction(analyzerContext.AnalyzeVariableDeclarator, OperationKind.VariableDeclarator); ctx.RegisterOperationAction(analyzerContext.AnalyzeConversion, OperationKind.Conversion); + ctx.RegisterOperationAction(analyzerContext.AnalyzeIsType, OperationKind.IsType); ctx.RegisterOperationAction(analyzerContext.AnalyzeIsPattern, OperationKind.IsPattern); ctx.RegisterOperationAction(analyzerContext.AnalyzeDelegateCreation, OperationKind.DelegateCreation); ctx.RegisterCompilationEndAction(analyzerContext.AnalyzeCompilationEnd); @@ -278,6 +279,15 @@ public void AnalyzeIsPattern(OperationAnalysisContext context) } } + public void AnalyzeIsType(OperationAnalysisContext context) + { + var operation = (IIsTypeOperation)context.Operation; + if (operation.TypeOperand is not null) + { + AddUsedType(operation, operation.TypeOperand); + } + } + public void AnalyzeDelegateCreation(OperationAnalysisContext context) { var operation = (IDelegateCreationOperation)context.Operation; diff --git a/tests/Meziantou.Analyzer.Test/Rules/AvoidUnusedInternalTypesAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/AvoidUnusedInternalTypesAnalyzerTests.cs index a63f74fdc..f0ca4a9f0 100644 --- a/tests/Meziantou.Analyzer.Test/Rules/AvoidUnusedInternalTypesAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/AvoidUnusedInternalTypesAnalyzerTests.cs @@ -1717,6 +1717,33 @@ await CreateProjectBuilder() .ValidateAsync(); } + [Fact] + public async Task InternalInterfaceOnlyUsedInTypeCheck_NoDiagnostic() + { + const string SourceCode = """ + public sealed class Foo + { + public static string? Run(object x) + { + if (x is IRunnable) + { + return null; + } + + return "X"; + } + } + + internal interface IRunnable + { + void Run(); + } + """; + await CreateProjectBuilder() + .WithSourceCode(SourceCode) + .ValidateAsync(); + } + [Fact] public async Task InternalRecordUsedInPatternMatching_NoDiagnostic() { From 17afa01db49760cabf77d8b407adfcba67f728a8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Apr 2026 19:50:49 +0000 Subject: [PATCH 3/3] Update NuGet.Protocol to 7.3.1 to fix NU1901 CI restore failure Agent-Logs-Url: https://github.com/meziantou/Meziantou.Analyzer/sessions/4cf831ee-70df-4c70-bd78-103452b389b4 Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com> --- src/ListDotNetTypes/ListDotNetTypes.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ListDotNetTypes/ListDotNetTypes.csproj b/src/ListDotNetTypes/ListDotNetTypes.csproj index a12ef279d..21fbb4c3f 100644 --- a/src/ListDotNetTypes/ListDotNetTypes.csproj +++ b/src/ListDotNetTypes/ListDotNetTypes.csproj @@ -6,7 +6,7 @@ - +