Don't crash on liften null left/right shift
authorMarek Safar <marek.safar@gmail.com>
Tue, 9 Nov 2010 19:23:24 +0000 (19:23 +0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 10 Nov 2010 09:05:43 +0000 (09:05 +0000)
mcs/errors/gcs0458-12.cs [new file with mode: 0644]
mcs/errors/gcs0458-13.cs [new file with mode: 0644]
mcs/mcs/cfold.cs

diff --git a/mcs/errors/gcs0458-12.cs b/mcs/errors/gcs0458-12.cs
new file mode 100644 (file)
index 0000000..fbc17fa
--- /dev/null
@@ -0,0 +1,11 @@
+// CS0458: The result of the expression is always `null' of type `int?'
+// Line: 9
+// Compiler options: -warnaserror -warn:2
+
+class C
+{
+       static void Foo()
+       {
+               var res = null >> 2;
+       }
+}
diff --git a/mcs/errors/gcs0458-13.cs b/mcs/errors/gcs0458-13.cs
new file mode 100644 (file)
index 0000000..7246847
--- /dev/null
@@ -0,0 +1,11 @@
+// CS0458: The result of the expression is always `null' of type `int?'
+// Line: 9
+// Compiler options: -warnaserror -warn:2
+
+class C
+{
+       static void Foo()
+       {
+               var res = null << 2;
+       }
+}
index 903526b8839d578e02833b5dd9d9e32a17d4214d..342b9b1328c595ffc07f1e716bc99059b29d3683 100644 (file)
@@ -850,6 +850,10 @@ namespace Mono.CSharp {
                                if (left.Type == TypeManager.uint32_type)
                                        return new UIntConstant (((UIntConstant)left).Value << lshift_val, left.Location);
 
+                               // null << value => null
+                               if (left is NullLiteral)
+                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+
                                left = left.ConvertImplicitly (ec, TypeManager.int32_type);
                                if (left.Type == TypeManager.int32_type)
                                        return new IntConstant (((IntConstant)left).Value << lshift_val, left.Location);
@@ -874,6 +878,10 @@ namespace Mono.CSharp {
                                if (left.Type == TypeManager.uint32_type)
                                        return new UIntConstant (((UIntConstant)left).Value >> rshift_val, left.Location);
 
+                               // null >> value => null
+                               if (left is NullLiteral)
+                                       return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+
                                left = left.ConvertImplicitly (ec, TypeManager.int32_type);
                                if (left.Type == TypeManager.int32_type)
                                        return new IntConstant (((IntConstant)left).Value >> rshift_val, left.Location);