Skip to content

Commit

Permalink
Fix analyzer RCS1182 (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Aug 17, 2024
1 parent cbf64f8 commit 5428aab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private static void AnalyzeBaseList(SyntaxNodeAnalysisContext context)

var isFirst = true;
INamedTypeSymbol typeSymbol = null;
SymbolInterfaceInfo baseClassInfo = default;
List<SymbolInterfaceInfo> baseInterfaceInfos = null;

foreach (BaseTypeSyntax baseType in baseTypes)
Expand All @@ -78,14 +77,9 @@ private static void AnalyzeBaseList(SyntaxNodeAnalysisContext context)
ImmutableArray<INamedTypeSymbol> 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);

Expand All @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : List<T>, [|IEnumerable<T>|] where T : class
{
}
", @"
await VerifyNoDiagnosticAsync(@"
using System.Collections.Generic;
class Foo1<T> : List<T> where T : class
class Foo1<T> : List<T>, IEnumerable<T> where T : class
{
}
");
Expand Down

0 comments on commit 5428aab

Please sign in to comment.