Fix S2094 FP: Primary constructor calling base class constructor #9011
Labels
Area: C#
C# rules related issues.
Area: C#12
C#12 related issues
Type: False Positive
Rule IS triggered when it shouldn't be.
Milestone
Description
A class with a primary ctor which calls a base class ctor but is otherwise empty produces a false positive S2094 (Remove this empty class, write its code or make it an "interface").
Repro steps
NUnit has the class
TestCaseData
which can be used to define parameters for test methods. Since the ctor ofTestCaseData
takes any objects, I often define a sub-class with a constructor to get some type safety and syntactic sugar that requires a known target type. With the new primary constructors in C# 12 this can be written in one line, for example:Expected behavior
The class
CountTestCaseData
has some behavior so it should not be considered empty.Actual behavior
The class
CountTestCaseData
produces S2094.Known workarounds
Reverting back to the old but functionally identical C# syntax does not produce the warning:
Related information
The text was updated successfully, but these errors were encountered: