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

Missing nullability warnings after invocation of extension methods with [AllowNull] this parameter #48134

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

Comments

@TessenR
Copy link

TessenR commented Sep 28, 2020

Version Used:

Branch master (26 Sep 2020)
Latest commit 3e38d76 by CyrusNajmabadi:
Merge pull request #48002 from CyrusNajmabadi/implicitCreation

Use implicit object creation in the IDE layers.

Steps to Reproduce:

Compile and run the following code:

#nullable enable
using System.Diagnostics.CodeAnalysis;

class Test
{
  public static void Main()
  {
      string? s = null;
      s.AllowNullExtension();
      s.ToString(); // no warnings, runtime crash
  }
}

public static class Extension
{
   public static void AllowNullExtension([AllowNull] this string p) { }
}

Expected Behavior:
Warning for s.ToString()

Actual Behavior:
No warnings. The program crashes at runtime with a NullReferenceException

@PathogenDavid
Copy link
Contributor

Worth noting that this is not specific to extension methods, it happens with normal methods too.

@RikkiGibson
Copy link
Contributor

This appears to be a corollary of #48605 and would likely be solved at the same time

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