Skip to content
New issue

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

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

Already on GitHub? # to your account

Incorrect CA2021 Warning #109344

Closed
sra-michaelgold opened this issue Oct 29, 2024 · 2 comments
Closed

Incorrect CA2021 Warning #109344

sra-michaelgold opened this issue Oct 29, 2024 · 2 comments
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@sra-michaelgold
Copy link

sra-michaelgold commented Oct 29, 2024

Description

Using 9.0.100-rc.2.24474.11 SDK

I'm getting incorrect CA2021 warning on valid code. See repro steps below.

Reproduction Steps

IEnumerable<BaseClass<int>> list = [new Implementation()];

var first = list.OfType<Implementation>().First();
Console.WriteLine(first.GetHashCode());


public abstract class BaseClass<T>
{
}

public sealed class Implementation : BaseClass<int>
{
}

Expected behavior

No warning

Actual behavior

Program.cs(3, 13): [CA2021] This call will always result in an empty sequence because type 'BaseClass' is incompatible with type 'Implementation' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2021)

Regression?

No response

Known Workarounds

Add NoWarn for CA2021 to csproj, but this is not optimal in case the issue actually exists.

Configuration

No response

Other information

9.0.100-rc.2.24474.11 SDK
Running in Rider 2024.2.7
Windows 10 x64

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 29, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Oct 29, 2024
@vcsjones
Copy link
Member

This looks like a duplicate of dotnet/roslyn-analyzers#7357.

I am going to close this as an existing issue has been identified in the appropriate repo, but feel free to re-open if you believe this was closed mistakenly.

@vcsjones vcsjones closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Oct 29, 2024
@sra-michaelgold
Copy link
Author

Thanks @vcsjones ! I agree it's a dupe. Apologies for not seeing the existing issue.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

2 participants