Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combination of implicit conversion, equality operator and nullables fails to compile after update from Visual Studio 2015.2 to 2015.3

Below code compiles in VS2015.2, but after upgrade to VS2015.3 it fails with error CS0019: Operator '==' cannot be applied to operands of type 'Registration<Something>' and 'Something'.

  public class Class1
  {
      public Class1()
      {
          var a = new Registration<Something>();
          var x = a == Something.Bad; // this line fails in VS2015.3
      }
  }

  public struct Registration<T> where T:struct
  {
      public static implicit operator T?(Registration<T> registration)
      {
          return null;
      }
  }

  public enum Something
  {
      Good,
      Bad
  }

I can not find any notice about such a change in the changelog for update 3. Can someone tell me, why this happens? And which is the correct behavior?

EDIT: Combination of implicit conversion, equality operator and nullables... and enums. This only seems to fail when T is an enum.

like image 875
asgerhallas Avatar asked Oct 30 '22 22:10

asgerhallas


1 Answers

Looks like a bug. We're tracking this as https://github.com/dotnet/roslyn/issues/13380

like image 70
Neal Gafter Avatar answered Nov 13 '22 06:11

Neal Gafter