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

Incorrect warnings reported for deconstruction with user-defined conversions and cannot be suppressed #36947

Open
TessenR opened this issue Jul 3, 2019 · 1 comment

Comments

@TessenR
Copy link

TessenR commented Jul 3, 2019

Version Used:

Branch master (21 Jun 2019)
Latest commit 898bed by Heejae Chang:
added NFW to get some data on incremental parsing bug where source si� (#36620)

* added NFW to get some data on incremental parsing bug where source size and tree size is different

* more comments

Steps to Reproduce:

Compile the following code:

#nullable enable
class C
{
  static void Main()
  {
      (B b1, B b2) = new C();
  }

  public extern void Deconstruct(out A? a1, out A a2);
}

class A { }
class B { public static extern implicit operator B(A a); }

Expected Behavior:
warning CS8600: Converting null literal or possible null value to non-nullable type. reported for the deconstruction source i.e. new C().
I believe it would be possible to suppress the warning if it is reported for new C()

Update:: Actually, I believe Roslyn should report CS8604: Possible null reference argument for parameter 'a' in 'B.implicit B'. instead of CS8600 here. This is what it reports without deconstruction e.g. (b1, _) = (a, "");

Actual Behavior:
The following two warnings are reported for the declaration expression B b1

warning CS8600: Converting null literal or possible null value to non-nullable type.
warning CS8624: Argument of type 'B' cannot be used as an output of type 'A' for parameter 'a1' in 'void C.Deconstruct(out A? a1, out A a2)' due to differences in the nullability of reference types.

The following warning is reported for the declaration expression B b2

warning CS8624: Argument of type 'B' cannot be used as an output of type 'A' for parameter 'a2' in 'void C.Deconstruct(out A? a1, out A a2)' due to differences in the nullability of reference types.

It's impossible to suppress any of these warnings as placing the suppression operator ! anywhere on the left side of the assignment results in compilation errors.

Notes
Reporting CS8600: Converting null literal or possible null value to non-nullable type. for the declaration expression B b1 seems strange and misleading as it's a declaration of a variable and null value cannot be assigned to it according to the conversion operator signature.
I'm pretty sure CS8624 warnings shouldn't be reported at all as there's no nullability mismatch between these types - they just aren't equal regardless of nullability annotations. Note that this warning is not reported if the conversion/assignment happens outside of a deconstruction e.g. B b = (A) null; // CS8600 only.
Note that current location for these warnings also makes it completely impossible to suppress them via the suppression operator !

@jinujoseph jinujoseph added this to Backlog (Critical) in IDE Nullability Work via automation Jul 3, 2019
@jinujoseph jinujoseph added this to the 16.3 milestone Jul 3, 2019
@jasonmalinowski jasonmalinowski removed this from Backlog (Critical) in IDE Nullability Work Jul 12, 2019
@jasonmalinowski
Copy link
Member

Moving to compiler -- this isn't an IDE bug.

@jcouv jcouv added this to Deconstruction in Nullable Board Jul 12, 2019
@jcouv jcouv modified the milestones: 16.3, Compiler.Next Jul 16, 2019
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Nullable Board
Deconstruction
Development

No branches or pull requests

5 participants