Open
Description
Analyzer
Diagnostic ID: CA1859: Use concrete types when possible for improved performance
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 8.0.101
Describe the bug
CA1859 is falsely raised when multiple derivatives are involved together with custom operator overwrites. Applying the suggested fix leads to compilation errors.
Repro
public abstract class Base
{
public static Base operator *(Base left, int right) => default;
}
public class A : Base;
public class B : Base;
public class Test
{
private static Base Foo(Base input)
// ^^^ CA1859
{
return input is A ? new B() : input * 4;
}
}
Actual behavior
CA1859 is raised for Test.Foo
method, suggesting to change the return type to B
Additional context
No warning is raised when either
- the
operator
ist replaced with a method likestatic Base Multiply(Base, int)
- the ternary operator in the return expression of
Test.Foo
is removed (e.g.return input * 4;)
Metadata
Metadata
Assignees
Labels
No labels
Activity