Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RCS0034 #1351

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
{
}");
}
}