Add more restrictions to custom attribute encoding
authorMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 10:41:08 +0000 (10:41 +0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 11:26:52 +0000 (11:26 +0000)
mcs/errors/cs0182-12.cs [new file with mode: 0644]
mcs/mcs/ecore.cs

diff --git a/mcs/errors/cs0182-12.cs b/mcs/errors/cs0182-12.cs
new file mode 100644 (file)
index 0000000..2827f63
--- /dev/null
@@ -0,0 +1,21 @@
+// CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression
+// Line: 18
+
+using System;
+
+enum E
+{ 
+       Value
+}
+
+class AAttribute : Attribute
+{ 
+       public AAttribute (Enum e)
+       {
+       }
+}
+
+[A (E.Value)]
+class Test
+{
+}
\ No newline at end of file
index 6f446757e445d443df8b174782f00f87cdacca65..183ae9e6f738f6efdde986bb4637c17dc8572b1a 100644 (file)
@@ -1458,6 +1458,12 @@ namespace Mono.CSharp {
 
                public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
                {
+                       // Only boxing to object type is supported
+                       if (targetType != TypeManager.object_type) {
+                               base.EncodeAttributeValue (rc, enc, targetType);
+                               return;
+                       }
+
                        enc.Encode (child.Type);
                        child.EncodeAttributeValue (rc, enc, child.Type);
                }