[Mono-bugs] [Bug 50839][Nor] New - typeof(void) in attribute parameters
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 11 Nov 2003 22:12:02 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by shugo@ruby-lang.org.
http://bugzilla.ximian.com/show_bug.cgi?id=50839
--- shadow/50839 2003-11-11 22:12:02.000000000 -0500
+++ shadow/50839.tmp.20365 2003-11-11 22:12:02.000000000 -0500
@@ -0,0 +1,184 @@
+Bug#: 50839
+Product: Mono/MCS
+Version: unspecified
+OS: GNU/Linux [Other]
+OS Details: Debian Sid
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: shugo@ruby-lang.org
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: typeof(void) in attribute parameters
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+
+Steps to reproduce the problem:
+1. compile test.cs
+
+$ cat test.cs
+using System;
+
+public class TestAttribute : Attribute {
+ Type type;
+
+ public TestAttribute(Type type)
+ {
+ this.type = type;
+ }
+
+ public Type Type
+ {
+ get { return type; }
+ }
+}
+
+[TestAttribute(typeof(void))]
+public class Test {
+ public static void Main()
+ {
+ object[] attrs =
+ typeof(Test).GetCustomAttributes(typeof(TestAttribute), false);
+ foreach (TestAttribute attr in attrs) {
+ Console.WriteLine("TestAttribute({0})", attr.Type);
+ }
+ }
+}
+$ mcs test.cs
+
+Actual Results:
+
+$ mcs test.cs
+test.cs(17) error CS0182: An attribute argument must be a constant
+expression, typeof expression or array creation expression
+Compilation failed: 1 error(s), 0 warnings
+
+Expected Results:
+
+$ mcs test.cs
+Compilation succeeded
+$ ./test.exe
+TestAttribute(System.Void)
+
+How often does this happen?
+
+Everytime.
+
+Additional Information:
+
+The following patch solves the problem.
+
+Index: mcs/attribute.cs
+===================================================================
+RCS file: /mono/mcs/mcs/attribute.cs,v
+retrieving revision 1.98
+diff -u -r1.98 attribute.cs
+--- mcs/attribute.cs 7 Nov 2003 07:01:27 -0000 1.98
++++ mcs/attribute.cs 12 Nov 2003 02:49:23 -0000
+@@ -137,8 +137,8 @@
+ if (e is Constant) {
+
+ result = ((Constant) e).GetValue ();
+
+ return true;
+
+- } else if (e is TypeOf) {
+
+- result = ((TypeOf) e).TypeArg;
+
++ } else if (e is ITypeOf) {
+
++ result = ((ITypeOf) e).TypeArg;
+
+ return true;
+
+ } else if (e is ArrayCreation){
+
+ result = ((ArrayCreation) e).EncodeAsAttribute ();
+
+@@ -293,8 +293,8 @@
+ this.Inherited = (bool) o;
+
+ }
+
+
+
+- } else if (e is TypeOf) {
+
+- prop_values.Add (((TypeOf) e).TypeArg);
+
++ } else if (e is ITypeOf) {
+
++ prop_values.Add (((ITypeOf) e).TypeArg);
+
+ } else {
+
+ Error_AttributeArgumentNotValid (Location);
+
+ return null;
+
+@@ -318,8 +318,8 @@
+ object value = ((Constant) e).GetValue ();
+
+
+
+ field_values.Add (value);
+
+- } else if (e is TypeOf) {
+
+- field_values.Add (((TypeOf) e).TypeArg);
+
++ } else if (e is ITypeOf) {
+
++ field_values.Add (((ITypeOf) e).TypeArg);
+
+ } else {
+
+ Error_AttributeArgumentNotValid (Location);
+
+ return null;
+
+Index: mcs/expression.cs
+===================================================================
+RCS file: /mono/mcs/mcs/expression.cs,v
+retrieving revision 1.497
+diff -u -r1.497 expression.cs
+--- mcs/expression.cs 8 Nov 2003 14:49:03 -0000 1.497
++++ mcs/expression.cs 12 Nov 2003 02:49:28 -0000
+@@ -6425,11 +6425,18 @@
+ ec.ig.Emit (OpCodes.Ldarg_0);
+ }
+ }
++
++ /// <summary>
++ /// This interface is implemented by typeof
++ /// </summary>
++ public interface ITypeOf {
++ Type TypeArg { get; }
++ }
+
+ /// <summary>
+ /// Implements the typeof operator
+ /// </summary>
+- public class TypeOf : Expression {
++ public class TypeOf : Expression, ITypeOf {
+ public readonly Expression QueriedType;
+ Type typearg;
+
+@@ -6471,7 +6478,7 @@
+ /// <summary>
+ /// Implements the `typeof (void)' operator
+ /// </summary>
+- public class TypeOfVoid : Expression {
++ public class TypeOfVoid : Expression, ITypeOf {
+ public TypeOfVoid (Location l)
+ {
+ loc = l;