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

CA1859 improperly handles explicit interface implementations on a parent class #6704

Closed
jnyrup opened this issue Jun 21, 2023 · 0 comments · Fixed by #6709
Closed

CA1859 improperly handles explicit interface implementations on a parent class #6704

jnyrup opened this issue Jun 21, 2023 · 0 comments · Fixed by #6709
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design False_Positive A diagnostic is reported for non-problematic case
Milestone

Comments

@jnyrup
Copy link

jnyrup commented Jun 21, 2023

Analyzer

Diagnostic ID: CA1859: Use concrete types when possible for improved performance

Analyzer source

SDK: Built-in CA analyzers in .NET 8 Preview 5 SDK

Version: 8.0.100-preview.5.23303.2

Describe the bug

#6416 described a false positive when a type explicitly implemented the interface method being invoked.
This issue is about when a parent class explicitly implements the interface method.

Steps To Reproduce

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AnalysisLevel>latest</AnalysisLevel>
  </PropertyGroup>
</Project>
class Class1
{
    public void NoWarning()
    {
        I obj = new Base();
        obj.M();
    }

    public void FalseWarning()
    {
        I obj = new Derived(); // <-- triggers CA1859
        obj.M();
    }
}

interface I
{
    void M();
}

class Base : I
{
    void I.M()
    {
    }
}

class Derived : Base
{
}

Expected behavior

CA1859 should not be triggered as M() is only explicitly implemented.

Actual behavior

CA1859 is triggered.

CA1859	Change type of variable 'obj' from 'I' to 'Derived' for improved performance

Additional context

@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-Microsoft.CodeAnalysis.NetAnalyzers False_Positive A diagnostic is reported for non-problematic case labels Jun 22, 2023
@mavasani mavasani added this to the .NET vNext milestone Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design False_Positive A diagnostic is reported for non-problematic case
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants