从Visual Studio 2015.2到2015.3更新后,隐式转换,等于运算符和nullables的组合无法编译

时间:2016-08-02 12:12:42

标签: c# visual-studio visual-studio-2015

下面的代码在VS2015.2中编译,但在升级到VS2015.3后,它失败了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
  }

我无法在更新3的更改日志中找到关于此类更改的任何通知。有人可以告诉我,为什么会发生这种情况?哪个是正确的行为?

编辑:隐式转换,等式运算符和nullables ...和枚举的组合。当T是枚举时,这似乎只会失败。

1 个答案:

答案 0 :(得分:2)

看起来像个错误。我们将其跟踪为https://github.com/dotnet/roslyn/issues/13380