2005-03-13 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Sun, 13 Mar 2005 07:46:28 +0000 (07:46 -0000)
committerMartin Baulig <martin@novell.com>
Sun, 13 Mar 2005 07:46:28 +0000 (07:46 -0000)
* expression.cs (Binary.ResolveOperator): For `==' and `!=', allow
comparing arbitrary types with the null literal.

svn path=/trunk/mcs/; revision=41748

mcs/gmcs/ChangeLog
mcs/gmcs/expression.cs

index af878a7473b9ed21c721bfb3a29a0ffa1f12932a..b4f63a501045d333c4a3bdda1b28298dbbc0d7da 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-13  Martin Baulig  <martin@ximian.com>
+
+       * expression.cs (Binary.ResolveOperator): For `==' and `!=', allow
+       comparing arbitrary types with the null literal.
+
 2005-03-13  Martin Baulig  <martin@ximian.com>
 
        * generic.cs (Nullable.LiftedBinaryOperator): Add support for the
index 6a3b617984b3b6cc105f005a94254145de931726..82bdf8fc894bf41874d5cadbe95c2a37b3e6595e 100644 (file)
@@ -2396,6 +2396,15 @@ namespace Mono.CSharp {
                                        return this;
                                }
 
+                               bool left_is_null = left is NullLiteral;
+                               bool right_is_null = right is NullLiteral;
+                               if (left_is_null || right_is_null) {
+                                       if (oper == Operator.Equality)
+                                               return new BoolLiteral (left_is_null == right_is_null);
+                                       else
+                                               return new BoolLiteral (left_is_null != right_is_null);
+                               }
+
                                //
                                // operator != (object a, object b)
                                // operator == (object a, object b)