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 update variables' nullability states on user-defined conversions #49136

Closed
TessenR opened this issue Nov 2, 2020 · 2 comments · Fixed by #49576
Closed

Roslyn doesn't update variables' nullability states on user-defined conversions #49136

TessenR opened this issue Nov 2, 2020 · 2 comments · Fixed by #49576

Comments

@TessenR
Copy link

TessenR commented Nov 2, 2020

Version Used:

Branch master (31 Oct 2020)
Latest commit e48c865 by msftbot[bot]:
Merge pull request #49097 from CyrusNajmabadi/fixAltKey

Fix the chording for inline hints.

Steps to Reproduce:

Compile the following code:

#nullable enable
using System.Diagnostics.CodeAnalysis;

class C
{
  void M1(int? x)
  {
    C c = x; // CS8607
    Method(x); // CS8607
  }

  void M2(int? x)
  {
    Method(x); // CS8607
    C c = x; // fine
  }
  
  void Method([DisallowNull] int? t) { }
  
  public static extern implicit operator C([DisallowNull] int? s);
}

Expected Behavior:
A single CS8607 warning in M1

Actual Behavior:
Two warnings are reported for M1 but only one for M2

Notes
Roslyn currently updates variables' nullability states on passing them to non-nullable parameters but for some reason ignores non-nullable parameters of user-defined conversion operators.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 2, 2020
@jaredpar
Copy link
Member

jaredpar commented Nov 6, 2020

@RikkiGibson seems like another possible corollary of #48605

@jaredpar jaredpar added Bug New Language Feature - Nullable Reference Types Nullable Reference Types and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 6, 2020
@RikkiGibson
Copy link
Contributor

might be due to #36164.

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

Successfully merging a pull request may close this issue.

4 participants