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

False positive IDE0004 and false negative CS0121 reported by the analyzer when calling certain kind of method overloads #72933

Closed
RedSaltyFish opened this issue Apr 8, 2024 · 4 comments · Fixed by #72939
Assignees
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it

Comments

@RedSaltyFish
Copy link

Version Used: 4.10.0-2.24124.2 (3059a07)

Steps to Reproduce:

  1. Define two overloads as shown below.
void Foo(char[] input)
{
    Console.WriteLine(input);
}

void Foo(string input)
{
    Console.WriteLine(input);
}
  1. Call the defined method.
Foo((char[])['h', 'e', 'l', 'l', 'o']);

Diagnostic Id: False positive IDE0004, false negative CS0121 if (char[]) conversion is removed.

Expected Behavior: Analyzer doesn't produce IDE0004 when the code is written as shown above and detects CS0121 when (char[]) conversion is removed.

Actual Behavior: False positive IDE0004 reported by analyzer suggesting (char[]) conversion is redundant. Remove (char[]) conversion and no CS0121 is reported by analyzer, but compiling it results in a CS0121 failure.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 8, 2024
@RedSaltyFish RedSaltyFish changed the title False positive IDE0004 and false negative CS0121 when calling certain kind of method overloads False positive IDE0004 and false negative CS0121 reported by the analyzer when calling certain kind of method overloads Apr 8, 2024
@CyrusNajmabadi CyrusNajmabadi removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 8, 2024
@CyrusNajmabadi CyrusNajmabadi self-assigned this Apr 8, 2024
@CyrusNajmabadi CyrusNajmabadi added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Apr 8, 2024
@CyrusNajmabadi
Copy link
Member

I don't repro this:

image

@cston @RikkiGibson did something change here?

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Apr 8, 2024

Yes I think we now require presence of an applicable Add method for non-empty collection-exprs in order for the conversion to exist via the "classic collection initializers" strategy, which causes the string overload to be non-applicable.

@CyrusNajmabadi
Copy link
Member

Ok. I'll add a test actually showing we expect this to work.

@CyrusNajmabadi
Copy link
Member

@RedSaltyFish this should go away once you upgrade to a more recent version of C# (which may or may not have been released yet :)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants