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

IDE0301 code fixer in ternary expression produces invalid C# code (CS0029) #76085

Closed
Sergio0694 opened this issue Nov 26, 2024 · 3 comments
Closed
Labels
Area-IDE Feature - IDE0301 Use collection expression for '.Empty'

Comments

@Sergio0694
Copy link
Contributor

Version Used: 4.12.0-3.24523.10 (16f58fa)'. Language version: 13.0

Steps to Reproduce:

  1. Paste this code in a blank new console:
using System.Collections.Immutable;

static IEnumerable<string> M(object obj)
{
    return obj is int
        ? Enumerable.Empty<string>()
        : Enumerable.Repeat("", 1);
}
  1. Hover over "Empty" and apply the suggested IDE0301 code fixer.

Diagnostic Id: IDE0301

Expected Behavior:

Should now get a code fixer here. Arguably you shouldn't get IDE0301 in the first place.

Actual Behavior:

You get IDE0301, and the code fixer breaks the code entirely:

Image

cc. @CyrusNajmabadi

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 26, 2024
@CyrusNajmabadi
Copy link
Member

Ide feature looks correct. This looks to be a parsing issue (parsing int?[] as an array of nullable ints instead of a conditional expr with a collection expr)

@arunchndr arunchndr added Feature - IDE0301 Use collection expression for '.Empty' Need More Info The issue needs more information to proceed. and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 26, 2024
@RikkiGibson
Copy link
Contributor

I'm not reproing on SharpLab (which I'm happy to see was updated today).

@dotnet-policy-service dotnet-policy-service bot added untriaged Issues and PRs which have not yet been triaged by a lead and removed Need More Info The issue needs more information to proceed. labels Nov 30, 2024
@CyrusNajmabadi
Copy link
Member

Fixed with #75328

@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature - IDE0301 Use collection expression for '.Empty'
Projects
None yet
Development

No branches or pull requests

4 participants