You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
staticvoidMain(){varvalue=new Value();// No Error CS0019 Operator '!=' cannot be applied to operands of type 'Value' and '<null>'if(value==null){// This line seems OK to the analyzer, but even the compiler is removing it.// Setting up break point here is removed to the next line when debugging.
Console.WriteLine("This is not even compiled.");}}
Expected Behavior:
The compiler or analyzer should issue CS0019 error.
Actual Behavior:
The code is built without any error and the code block inside the if is omitted.
This really stung me in one of my projects where I had to make what once was a class to a struct and I expected that the compiler will warn me of places where I compared it to null or not null.
If the value type doesn't have the custom operators == and != the code doesn't compile and the expected error CS0019 is given.
The text was updated successfully, but these errors were encountered:
zlatanov
changed the title
Struct type with custom operator == and
Struct types with custom equality operators no longer report CS0019 error when compared with null.
Aug 22, 2017
@zlatanov Just to confirm, you don't think this is a regression, correct?
I tried this on csc.exe version 1.3.2 (which shipped in the latest update of Visual Studio 2015) and also the previous/native csc.exe compiler and I get the same behavior.
@jcouv No, I don't think this is a regression. Just never had the case before where something was class that I needed it to be a struct ( with custom operators ) to notice it.
jcouv
changed the title
Struct types with custom equality operators no longer report CS0019 error when compared with null.
Struct types with custom equality operators doesn't report CS0019 error when compared with null.
Aug 28, 2017
Thanks for the clarification. Updated the title.
Adding a new warning is a breaking change, and so needs to be considered as part of warning waves (see #1580 for broader workitem).
Version Used:
Visual Studio 15.3.1
Steps to Reproduce:
Expected Behavior:
The compiler or analyzer should issue CS0019 error.
Actual Behavior:
The code is built without any error and the code block inside the if is omitted.
This really stung me in one of my projects where I had to make what once was a class to a struct and I expected that the compiler will warn me of places where I compared it to
null
ornot null
.If the value type doesn't have the custom operators == and != the code doesn't compile and the expected error CS0019 is given.
The text was updated successfully, but these errors were encountered: