From 9a73f494367d888af637e88e69528979e9d2cc90 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Wed, 14 Aug 2024 00:02:13 +0200 Subject: [PATCH 1/2] update --- .../RemoveRedundantBaseInterfaceAnalyzer.cs | 18 ++---------------- ...RCS1182RemoveRedundantBaseInterfaceTests.cs | 10 ++-------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/Analyzers/CSharp/Analysis/RemoveRedundantBaseInterfaceAnalyzer.cs b/src/Analyzers/CSharp/Analysis/RemoveRedundantBaseInterfaceAnalyzer.cs index 3e3b891a2e..5f673d1154 100644 --- a/src/Analyzers/CSharp/Analysis/RemoveRedundantBaseInterfaceAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/RemoveRedundantBaseInterfaceAnalyzer.cs @@ -63,7 +63,6 @@ private static void AnalyzeBaseList(SyntaxNodeAnalysisContext context) var isFirst = true; INamedTypeSymbol typeSymbol = null; - SymbolInterfaceInfo baseClassInfo = default; List baseInterfaceInfos = null; foreach (BaseTypeSyntax baseType in baseTypes) @@ -78,14 +77,9 @@ private static void AnalyzeBaseList(SyntaxNodeAnalysisContext context) ImmutableArray allInterfaces = baseSymbol.AllInterfaces; if (typeKind == TypeKind.Class) - { - if (!isFirst) - break; + return; - if (allInterfaces.Any()) - baseClassInfo = new SymbolInterfaceInfo(baseType, baseSymbol, allInterfaces); - } - else if (typeKind == TypeKind.Interface) + if (typeKind == TypeKind.Interface) { var baseInterfaceInfo = new SymbolInterfaceInfo(baseType, baseSymbol, allInterfaces); @@ -102,14 +96,6 @@ private static void AnalyzeBaseList(SyntaxNodeAnalysisContext context) Analyze(baseInterfaceInfo2, baseInterfaceInfo); } } - - if (baseClassInfo.Symbol is not null) - { - if (typeSymbol is null) - typeSymbol = context.SemanticModel.GetDeclaredSymbol((TypeDeclarationSyntax)baseList.Parent, context.CancellationToken); - - Analyze(baseInterfaceInfo, baseClassInfo); - } } } diff --git a/src/Tests/Analyzers.Tests/RCS1182RemoveRedundantBaseInterfaceTests.cs b/src/Tests/Analyzers.Tests/RCS1182RemoveRedundantBaseInterfaceTests.cs index bf59660d98..70eff56b64 100644 --- a/src/Tests/Analyzers.Tests/RCS1182RemoveRedundantBaseInterfaceTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1182RemoveRedundantBaseInterfaceTests.cs @@ -15,16 +15,10 @@ public class RCS1182RemoveRedundantBaseInterfaceTests : AbstractCSharpDiagnostic [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.RemoveRedundantBaseInterface)] public async Task Test_IEnumerableOfT() { - await VerifyDiagnosticAndFixAsync(@" -using System.Collections.Generic; - -class Foo1 : List, [|IEnumerable|] where T : class -{ -} -", @" + await VerifyNoDiagnosticAsync(@" using System.Collections.Generic; -class Foo1 : List where T : class +class Foo1 : List, IEnumerable where T : class { } "); From 26851092bee8ae4721054e88363f1172b54ad883 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sat, 17 Aug 2024 10:20:38 +0200 Subject: [PATCH 2/2] changelog --- ChangeLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index bab2e812da..f9ccdfc8bd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix analyzer [RCS1182](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1182) ([PR](https://github.com/dotnet/roslynator/pull/1502)) + ## [4.12.4] - 2024-06-01 ### Fixed