[mcs] Don't do empty array interpolation on user code, weird code expects empty array...
authorMarek Safar <marek.safar@gmail.com>
Tue, 19 Apr 2016 17:14:44 +0000 (19:14 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 19 Apr 2016 17:14:44 +0000 (19:14 +0200)
mcs/mcs/cs-parser.jay
mcs/mcs/expression.cs
mcs/tests/test-934.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index b0c771f7207b2eb26aa12a288bd58e11f811aae3..6783a7edbb672ef70e00d3684e3f35427ea12eab 100644 (file)
@@ -3926,7 +3926,9 @@ array_creation_expression
                if ($4 == null)
                        report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
 
-               $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
+               $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
+                       NoEmptyInterpolation = true
+               };
          }
        | NEW rank_specifier array_initializer
          {
index 76bcdbfa0ee7bdf8109573a1e6db43c9b9797deb..b011b264250dab49906455a83bc8e0fe8f7ea3a0 100644 (file)
@@ -7862,6 +7862,8 @@ namespace Mono.CSharp
                {
                }
 
+               public bool NoEmptyInterpolation { get; set; }
+
                public ComposedTypeSpecifier Rank {
                        get {
                                return this.rank;
@@ -8398,7 +8400,7 @@ namespace Mono.CSharp
 
                public override void Emit (EmitContext ec)
                {
-                       if (EmitOptimizedEmpty (ec))
+                       if (!NoEmptyInterpolation && EmitOptimizedEmpty (ec))
                                return;
 
                        var await_field = EmitToFieldSource (ec);
diff --git a/mcs/tests/test-934.cs b/mcs/tests/test-934.cs
new file mode 100644 (file)
index 0000000..ba464e3
--- /dev/null
@@ -0,0 +1,22 @@
+class X
+{
+       public static int Main ()
+       {
+               var a = new byte[] { };
+               var b = new byte[] { };
+               if (a.Equals (b))
+                       return 1;
+
+               if (ReferenceEquals (a, b))
+                       return 2;
+
+               b = new byte[0];
+               if (a.Equals (b))
+                       return 3;
+
+               if (ReferenceEquals (a, b))
+                       return 4;
+
+               return 0;
+       }
+}
\ No newline at end of file
index 30bf5ea7293b468b679e96149f4c48a38bb0529b..a395cb4cf763feba3bc83cb76ee5ffd691bc5c08 100644 (file)
     </type>
     <type name="ExtensibleTester`1[U]">
       <method name="Void Direct()" attrs="134">
-        <size>24</size>
+        <size>25</size>
       </method>
       <method name="Void .ctor(U)" attrs="6278">
         <size>15</size>
     </type>
     <type name="TestIssue.Program">
       <method name="Int32 Main()" attrs="150">
-        <size>31</size>
+        <size>32</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
         <size>7</size>
       </method>
       <method name="Int32 Main()" attrs="150">
-        <size>36</size>
+        <size>37</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
   <test name="test-555.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="150">
-        <size>360</size>
+        <size>361</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
       </method>
     </type>
   </test>
+  <test name="test-934.cs">
+    <type name="X">
+      <method name="Int32 Main()" attrs="150">
+        <size>106</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-94.cs">
     <type name="Base">
       <method name="Int32 IVehicle.Start()" attrs="481">
         <size>14</size>
       </method>
       <method name="Boolean MoveNext()" attrs="486">
-        <size>167</size>
+        <size>168</size>
       </method>
       <method name="Void Dispose()" attrs="486">
         <size>15</size>