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

Roslyn doesn't understand tuple expression syntax in switches when analyzing nullability #44127

Closed
TessenR opened this issue May 11, 2020 · 1 comment

Comments

@TessenR
Copy link

TessenR commented May 11, 2020

Version Used:

commit 27654b066e600a350706a13ebd67d1da542c1a7b
Merge: 436d17816f6 0c9f90368a5
Author: msftbot[bot] <48340428+msftbot[bot]@users.noreply.github.com>
Date:   Thu May 7 05:33:48 2020 +0000

    Merge pull request #44029 from dotnet/merges/release/dev16.7-preview1-to-master

    Merge release/dev16.7-preview1 to master

Steps to Reproduce:

Compile the following code:

using System;

public class C
{
  public void Test1(string? x)
  {
    switch (x)
    {
      case string _:
        Console.WriteLine(x.Length); // no warnings
        break;
    }
  }

  public void Test2(string? x)
  {
    switch (x, 1)
    {
      case (string _, _):
        Console.WriteLine(x.Length); // False CS8602: Dereference of a possibly null reference.
        break;
    }
  }
}

public class D
{
  public void Test1(string x)
  {
    switch (x)
    {
      case null:
        Console.WriteLine(x.Length); // CS8602: Dereference of a possibly null reference.
        break;
    }
  }

  public void Test2(string x)
  {
    switch (x, 1)
    {
      case (null, _):
        Console.WriteLine(x.Length); // missing warning
        break;
    }
  }
}

Expected Behavior:
No warnings in both methods in class C
Warnings in both methods in class D

Actual Behavior:
Roslyn doesn't update matched variables' nullability when a switche's governing expression is a tuple expression

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Apr 13, 2021

Fixed by #51001. /cc @jcouv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants