[mcs] Don't emit param-array attribute on method overrides, it's ignored by C# compil...
authorMarek Safar <marek.safar@gmail.com>
Tue, 30 May 2017 17:30:43 +0000 (19:30 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 30 May 2017 17:36:13 +0000 (19:36 +0200)
mcs/mcs/parameter.cs
mcs/tests/test-945.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 275f1013e8b9dfb533215ddeaeb466e4d4a8faf9..1360dbdfd65c3cc4144c8e26b052c4fb200e796f 100644 (file)
@@ -142,6 +142,9 @@ namespace Mono.CSharp {
        }
 
        public class ParamsParameter : Parameter {
+
+               bool ParamsAttributeEmit;
+
                public ParamsParameter (FullNamedExpression type, string name, Attributes attrs, Location loc):
                        base (type, name, Parameter.Modifier.PARAMS, attrs, loc)
                {
@@ -158,13 +161,18 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       var mc = ec as MemberCore;
+                       ParamsAttributeEmit = mc == null || (mc.ModFlags & Modifiers.OVERRIDE) == 0;
+
                        return parameter_type;
                }
 
                public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
                {
                        base.ApplyAttributes (mb, cb, index, pa);
-                       pa.ParamArray.EmitAttribute (builder);
+
+                       if (ParamsAttributeEmit)
+                               pa.ParamArray.EmitAttribute (builder);
                }
        }
 
diff --git a/mcs/tests/test-945.cs b/mcs/tests/test-945.cs
new file mode 100644 (file)
index 0000000..398787d
--- /dev/null
@@ -0,0 +1,22 @@
+public abstract class A
+{
+       public abstract void Bind (string [] args);
+}
+
+public class B : A
+{
+       public override void Bind (params string [] args)
+       {
+       }
+
+       public static int Main ()
+       {
+               var m = typeof (B).GetMethod ("Bind");
+               var p = m.GetParameters ();
+               var ca = p[0].GetCustomAttributes (false);
+               if (ca.Length != 0)
+                       return 1;
+               
+               return 0;
+       }
+}
index 79635e22c07770ecb0c5bcd7c43559443068cc1f..ba198950ecb0d34e6f3ae94feaf94a94fdd5f11a 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-945.cs">
+    <type name="A">
+      <method name="Void Bind(System.String[])" attrs="1478">
+        <size>0</size>
+      </method>
+      <method name="Void .ctor()" attrs="6276">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="B">
+      <method name="Void Bind(System.String[])" attrs="198">
+        <size>2</size>
+      </method>
+      <method name="Int32 Main()" attrs="150">
+        <size>63</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-95.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">