Fix nullable binary comparison with lifted unboxed expression. Fixes #4340
authorMarek Safar <marek.safar@gmail.com>
Tue, 10 Apr 2012 11:32:46 +0000 (12:32 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 10 Apr 2012 11:32:46 +0000 (12:32 +0100)
mcs/mcs/nullable.cs
mcs/tests/gtest-568.cs [new file with mode: 0644]
mcs/tests/gtest-etree-01.cs
mcs/tests/ver-il-net_4_5.xml

index 5afa7ea447e0d39fa86ad88254a9849a85118753..9397486a3362a1fe46b522f0300eb379c2a3d5a1 100644 (file)
@@ -860,7 +860,7 @@ namespace Mono.CSharp.Nullable
                                if (lifted_type == null)
                                        return null;
 
-                               if (left is UserCast || left is TypeCast)
+                               if (left is UserCast || left is EmptyCast || left is OpcodeCast)
                                        left.Type = lifted_type;
                                else
                                        left = EmptyCast.Create (left, lifted_type);
@@ -875,7 +875,7 @@ namespace Mono.CSharp.Nullable
                                if (r is ReducedExpression)
                                        r = ((ReducedExpression) r).OriginalExpression;
 
-                               if (r is UserCast || r is TypeCast)
+                               if (r is UserCast || r is EmptyCast || r is OpcodeCast)
                                        r.Type = lifted_type;
                                else
                                        right = EmptyCast.Create (right, lifted_type);
diff --git a/mcs/tests/gtest-568.cs b/mcs/tests/gtest-568.cs
new file mode 100644 (file)
index 0000000..9fb73a4
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+
+class X
+{
+       static int Main ()
+       {
+               object o = 10;
+               int? x = 3;
+
+               if ((int) o < x) {
+                       return 1;
+               }
+               
+               if (x > (int) o) {
+                       return 2;
+               }
+               
+               return 0;
+       }
+}
index 18854ead8dbe9a07fdc39eb41d197d028ed72f5c..c511e8580617eb6c0a8312dd2109422878ec9267 100644 (file)
@@ -1557,6 +1557,15 @@ class Tester
                Assert (false, e8.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
        }
 
+       void LessThanTest_9 ()
+       {
+               Expression<Func<object, int?, bool>> e = (a, b) => (int) a < b;
+               AssertNodeType (e, ExpressionType.LessThan);
+               Assert (false, e.Compile ().Invoke (1, null));
+               Assert (false, e.Compile ().Invoke (3, 3));
+               Assert (true, e.Compile ().Invoke (1, 3));
+       }
+
        void LessThanOrEqualTest ()
        {
                Expression<Func<int, int, bool>> e = (int a, int b) => a <= b;
index 9d9aa109bbcf2bb1df0053a1adb3cfef8eb35fcc..16b771c3a1593b0688f665b3f5f8f2bb7ab7aaae 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-568.cs">
+    <type name="X">
+      <method name="Int32 Main()" attrs="145">
+        <size>111</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anontype-01.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="145">
         <size>21</size>
       </method>
     </type>
+    <type name="Tester">
+      <method name="Void LessThanTest_9()" attrs="129">
+        <size>199</size>
+      </method>
+    </type>
   </test>
   <test name="gtest-etree-02.cs">
     <type name="M">