Skip to content

Incorrect suggestion to use discard pattern breaks compilation #45768

@TessenR

Description

@TessenR

Version Used:

Microsoft Visual Studio Professional 2019 Preview
Version 16.7.0 Preview 3.1
VisualStudio.16.Preview/16.7.0-pre.3.1+30223.230
Microsoft .NET Framework
Version 4.8.03752

Steps to Reproduce:

static class Program
{
  public static void Main()
  {
    switch ("".Length)
    {
      case var i when "".Length switch { var y => y > 0 }:
      {
        break;
      }
    }
  }
}

Expected Behavior:
The suggestion to remove the variable i doesn't break compilation

Actual Behavior:
The code is not compileable after the "fix"
image

static class Program
{
  public static void Main()
  {
    switch ("".Length)
    {
      case _ when "".Length switch { var y => y > 0 }:
      {
        break;
      }
    }
  }
}
Error CS0103: The name '_' does not exist in the current context (12, 12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions