-
Notifications
You must be signed in to change notification settings - Fork 239
Closed
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.
Milestone
Description
Description
S2743 raises a warning when non-generic static fields are declared in a generic type. The recommendation is to move these fields to a non-generic base class (or create one if it doesn't exist).
Such a solution is not feasible if the base type is also generic, as the same issue would be raised there.
This FP is also raised in the sonar-dotnet repo.
Repro steps
class BaseClass<T> { }
class DerivedClass<T> : BaseClass<T>
{
private static readonly string[] field = new[] { "a", "b", "c" }; // FP
public string[] SomeMethod() => field;
}Expected behavior
S2743 should not be raised.
Actual behavior
S2743 is raised on the static field.
Known workarounds
None.
Related information
- C#/VB.NET Plugins version: 9.4
- Visual Studio version: 17.6
- MSBuild / dotnet version: .NET 7.0
- Operating System: Windows 10 (10.0.19045)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.