Skip to content

Commit

Permalink
Fix RCS0034 (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Jan 8, 2024
1 parent 01b887f commit 8ffa81f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 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 [RCS0034](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0034) ([PR](https://github.com/dotnet/roslynator/pull/1351))

## [4.8.0] - 2024-01-02

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ private static void AnalyzeTypeDeclaration(SyntaxNodeAnalysisContext context)

SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses = typeDeclaration.ConstraintClauses;

TypeParameterListSyntax typeParameterList = typeDeclaration.TypeParameterList;
BaseTypeSyntax baseType = typeDeclaration.BaseList?.Types.LastOrDefault();

if (typeParameterList is null)
return;

Analyze(context, typeParameterList.GreaterThanToken, constraintClauses);
if (baseType is not null)
{
Analyze(context, baseType, constraintClauses);
}
else if (typeDeclaration.TypeParameterList is not null)
{
Analyze(context, typeDeclaration.TypeParameterList.GreaterThanToken, constraintClauses);
}
}

private static void AnalyzeDelegateDeclaration(SyntaxNodeAnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,23 @@ class C<T> where T : struct
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.PutTypeParameterConstraintOnItsOwnLine)]
public async Task TestNoDiagnostic_BaseType()
{
await VerifyNoDiagnosticAsync(@"
using System;
public interface IBaseInterface<TType, TKey>
where TType : class
where TKey : struct, IEquatable<TKey>
{
}
public interface IInterface<TType, TKey> : IBaseInterface<TType, TKey>
where TType : class
where TKey : struct, IEquatable<TKey>
{
}");
}
}

0 comments on commit 8ffa81f

Please sign in to comment.