[mcs] Emit partial type parameters attributes too
authorMarek Safar <marek.safar@gmail.com>
Mon, 30 Jun 2014 15:23:33 +0000 (17:23 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 30 Jun 2014 15:25:27 +0000 (17:25 +0200)
mcs/errors/cs0579-9.cs [new file with mode: 0644]
mcs/mcs/class.cs
mcs/mcs/generic.cs
mcs/mcs/method.cs
mcs/tests/test-partial-26.cs
mcs/tests/ver-il-net_4_5.xml

diff --git a/mcs/errors/cs0579-9.cs b/mcs/errors/cs0579-9.cs
new file mode 100644 (file)
index 0000000..43461af
--- /dev/null
@@ -0,0 +1,22 @@
+// CS0579: The attribute `TestAttributesCollecting.A' cannot be applied multiple times
+// Line: 19
+
+using System;
+
+namespace TestAttributesCollecting
+{
+       class A : Attribute
+       {
+               public A (int a)
+               {
+               }
+       }
+
+       partial class G1<[A (1)]T>
+       {
+       }
+
+       partial class G1<[A (2)]T>
+       {
+       }
+}
index 0cf97b22e94396b25c5d03f755d3a7aca31e9cf1..96f9188898788e19b823cbf611ae418e948d5408 100644 (file)
@@ -1775,7 +1775,7 @@ namespace Mono.CSharp
 
                protected virtual bool DoResolveTypeParameters ()
                {
-                       var tparams = CurrentTypeParameters;
+                       var tparams = MemberName.TypeParameters;
                        if (tparams == null)
                                return true;
 
@@ -1787,6 +1787,20 @@ namespace Mono.CSharp
                                        error = true;
                                        return false;
                                }
+
+                               if (IsPartialPart) {
+                                       var pc_tp = PartialContainer.CurrentTypeParameters [i];
+
+                                       tp.Create (spec, this);
+                                       tp.Define (pc_tp);
+
+                                       if (tp.OptAttributes != null) {
+                                               if (pc_tp.OptAttributes == null)
+                                                       pc_tp.OptAttributes = tp.OptAttributes;
+                                               else
+                                                       pc_tp.OptAttributes.Attrs.AddRange (tp.OptAttributes.Attrs);
+                                       }
+                               }
                        }
 
                        if (IsPartialPart) {
index c33583e49ae46a865b7996f72869c4524c0ea168..57afe77b004f424864eaba0104e9e04d1e99a764 100644 (file)
@@ -620,6 +620,11 @@ namespace Mono.CSharp {
                        spec.SetMetaInfo (type);
                }
 
+               public void Define (TypeParameter tp)
+               {
+                       builder = tp.builder;
+               }
+
                public void EmitConstraints (GenericTypeParameterBuilder builder)
                {
                        var attr = GenericParameterAttributes.None;
index 32d76fbc8c8b0c9ee16d8cd41726cd3ee96a3fab..2399133a9f1d372b1e89385ca994244660e62ca2 100644 (file)
@@ -1335,6 +1335,12 @@ namespace Mono.CSharp {
                                if (IsPartialDefinition) {
                                        if (partialMethodImplementation != null && CurrentTypeParameters != null) {
                                                CurrentTypeParameters.CheckPartialConstraints (partialMethodImplementation);
+
+                                               var otp = partialMethodImplementation.CurrentTypeParameters;
+                                               for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
+                                                       var tp = CurrentTypeParameters [i];
+                                                       tp.Define (otp[i]);
+                                               }
                                        }
 
                                        return;
@@ -1392,17 +1398,40 @@ namespace Mono.CSharp {
 
                        // Ensure we are always using method declaration parameters
                        for (int i = 0; i < methodDefinition.parameters.Count; ++i ) {
-                               parameters [i].Name = methodDefinition.parameters [i].Name;
-                               parameters [i].DefaultValue = methodDefinition.parameters [i].DefaultValue;
+                               var md_p = methodDefinition.parameters [i];
+                               var p = parameters [i];
+                               p.Name = md_p.Name;
+                               p.DefaultValue = md_p.DefaultValue;
+                               if (md_p.OptAttributes != null) {
+                                       if (p.OptAttributes == null) {
+                                               p.OptAttributes = md_p.OptAttributes;
+                                       } else {
+                                               p.OptAttributes.Attrs.AddRange (md_p.OptAttributes.Attrs);
+                                       }
+                               }
                        }
 
-                       if (methodDefinition.attributes == null)
-                               return;
+                       if (methodDefinition.attributes != null) {
+                               if (attributes == null) {
+                                       attributes = methodDefinition.attributes;
+                               } else {
+                                       attributes.Attrs.AddRange (methodDefinition.attributes.Attrs);
+                               }
+                       }
 
-                       if (attributes == null) {
-                               attributes = methodDefinition.attributes;
-                       } else {
-                               attributes.Attrs.AddRange (methodDefinition.attributes.Attrs);
+                       if (CurrentTypeParameters != null) {
+                               for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
+                                       var tp_other = methodDefinition.CurrentTypeParameters [i];
+                                       if (tp_other.OptAttributes == null)
+                                               continue;
+
+                                       var tp = CurrentTypeParameters [i];
+                                       if (tp.OptAttributes == null) {
+                                               tp.OptAttributes = tp_other.OptAttributes;
+                                       } else {
+                                               tp.OptAttributes.Attrs.AddRange (tp.OptAttributes.Attrs);
+                                       }
+                               }
                        }
                }
        }
index 54cfb9cb4e19d1e7892bca2c9278428940d6b1f1..78a543212d0eff01cfc57433458f86d9f7a75a0f 100644 (file)
@@ -1,21 +1,25 @@
 using System;
 
-namespace ConsoleApplication1
+namespace TestAttributesCollecting
 {
+       class A : Attribute
+       {
+       }
+
        public partial class X
        {
-               [CLSCompliant (true)]
-               partial void Foo ();
+               [A]
+               partial void Foo<[A] T>(/*[A]*/ int p);
        }
 
        public partial class X
        {
-               partial void Foo ()
+               partial void Foo<T> (int p)
                {
                        int i;
                }
        }
-       
+
        public partial class Y
        {
                partial void Foo ()
@@ -23,7 +27,7 @@ namespace ConsoleApplication1
                        int i;
                }
        }
-       
+
        public partial class Y
        {
                [CLSCompliant (true)]
@@ -34,16 +38,22 @@ namespace ConsoleApplication1
        {
                public static int Main ()
                {
-                       var x = typeof (X).GetMethod ("Foo", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetCustomAttributes (true);
+                       var m = typeof (X).GetMethod ("Foo", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+                       var x = m.GetCustomAttributes (true);
                        Console.WriteLine (x.Length);
                        if (x.Length != 1)
                                return 1;
 
+                       var ga = m.GetGenericArguments ();
+                       x = ga [0].GetCustomAttributes (false);
+                       if (x.Length != 1)
+                               return 2;
+
                        x = typeof (Y).GetMethod ("Foo", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetCustomAttributes (true);
                        Console.WriteLine (x.Length);
                        if (x.Length != 1)
-                               return 2;
-                       
+                               return 3;
+
                        return 0;
                }
        }
index 5d85247e3a2216780a95965417583fec831246f8..9b31a234fccc5242371c8a111a843f639478b8d0 100644 (file)
     </type>\r
   </test>\r
   <test name="test-partial-26.cs">\r
-    <type name="ConsoleApplication1.X">\r
-      <method name="Void Foo()" attrs="129">\r
+    <type name="TestAttributesCollecting.A">\r
+      <method name="Void .ctor()" attrs="6278">\r
+        <size>7</size>\r
+      </method>\r
+    </type>\r
+    <type name="TestAttributesCollecting.X">\r
+      <method name="Void Foo[T](Int32)" attrs="129">\r
         <size>2</size>\r
       </method>\r
       <method name="Void .ctor()" attrs="6278">\r
         <size>7</size>\r
       </method>\r
     </type>\r
-    <type name="ConsoleApplication1.Y">\r
+    <type name="TestAttributesCollecting.Y">\r
       <method name="Void Foo()" attrs="129">\r
         <size>2</size>\r
       </method>\r
         <size>7</size>\r
       </method>\r
     </type>\r
-    <type name="ConsoleApplication1.Program">\r
+    <type name="TestAttributesCollecting.Program">\r
       <method name="Int32 Main()" attrs="150">\r
-        <size>116</size>\r
+        <size>151</size>\r
       </method>\r
       <method name="Void .ctor()" attrs="6278">\r
         <size>7</size>\r