2007-03-09 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Tue, 13 Mar 2007 13:28:28 +0000 (13:28 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 13 Mar 2007 13:28:28 +0000 (13:28 -0000)
* enum.cs (Enum): Make this a TypeContainer.
(EnumMember): Derive from `Const'.

* const.cs
(Const.DoResolveValue): New protected virtual method; move most of
the functionality of ResolveValue() here so we can override it in
`EnumMember'.
(Const.CreateConstantReference): Make this virtual.

* class.cs (Kind): Add `Kind.Enum'.
(TypeContainer.Emit): Don't emit the enums here; they're already
in the `RootContext.typecontainer_resolve_order'.

* rootcontext.cs (RootContext.EmitCode): Don't emit the enums
here; they're already in the `typecontainer_resolve_order'.

* ecore.cs (EnumConstant.ConvertImplicitly): Add
TypeManager.DropGenericTypeArguments().

* typemanager.cs
(TypeManager.CSharpEnumValue): Add DropGenericTypeArguments().
(TypeManager.IsEnumType): Likewise.
(TypeManager.EnumToUnderlying): Likewise.
(TypeManager.IsEqual): Add support for enums.

svn path=/trunk/mcs/; revision=74168

14 files changed:
mcs/errors/cs0110-2.cs
mcs/errors/cs3005-13.cs
mcs/errors/cs3005-15.cs
mcs/gmcs/cs-parser.jay
mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/const.cs
mcs/mcs/cs-parser.jay
mcs/mcs/ecore.cs
mcs/mcs/enum.cs
mcs/mcs/rootcontext.cs
mcs/mcs/statement.cs
mcs/mcs/typemanager.cs
mcs/tests/gtest-313.cs [new file with mode: 0755]

index 342d990ca007383229ff9b769d4ada72058e96b4..cb069f15e7d78798f9c58245fe282ffb8dba012a 100644 (file)
@@ -1,4 +1,4 @@
-// cs0110.cs: The evaluation of the constant value for `E.c' involves a circular definition
+// cs0110.cs: The evaluation of the constant value for `E.a' involves a circular definition
 // Line: 6
 
 enum E
index 92f8c1e7bfdbde45f531b9e27b33646915bba023..8d820904c898dbb9e7eb0d71f9e18bd0b0ad6ee3 100644 (file)
@@ -1,4 +1,4 @@
-// cs3005-13.cs: Identifier `CLSEnum.Label' differing only in case is not CLS-compliant
+// cs3005-13.cs: Identifier `CLSEnum.label' differing only in case is not CLS-compliant
 // Line: 9
 // Compiler options: -warnaserror
 
index 69001a3fc1fdf5642f3f0a63174afe6a3c16a483..983094434fa2c9ec133b36fe3bafcc60b60b42ef 100644 (file)
@@ -1,4 +1,4 @@
-// cs3005-15.cs: Identifier `a' differing only in case is not CLS-compliant
+// cs3005-15.cs: Identifier `A' differing only in case is not CLS-compliant
 // Line: 10
 // Compiler options: -warnaserror
 
index 6958b1844678045358c3bc3313a420a0176c5e07..f0eda52a3f8d447ca87cfae764cb5855b65e484d 100644 (file)
@@ -2678,8 +2678,9 @@ enum_declaration
 
                EnumMember em = null;
                foreach (VariableDeclaration ev in (ArrayList) $7) {
-                       em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
-                               new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
+                       em = new EnumMember (
+                               e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
+                               ev.OptAttributes, ev.Location);
 
 //                     if (RootContext.Documentation != null)
                                em.DocComment = ev.DocComment;
index 19a0449f5ecee1ba8e1266ffd0369376293d33c2..1e4676f7acfd5beb12fda85a523af2b6dade312b 100644 (file)
@@ -1,3 +1,30 @@
+2007-03-09  Martin Baulig  <martin@ximian.com>
+
+       * enum.cs (Enum): Make this a TypeContainer.
+       (EnumMember): Derive from `Const'.
+
+       * const.cs
+       (Const.DoResolveValue): New protected virtual method; move most of
+       the functionality of ResolveValue() here so we can override it in
+       `EnumMember'.
+       (Const.CreateConstantReference): Make this virtual.
+
+       * class.cs (Kind): Add `Kind.Enum'.
+       (TypeContainer.Emit): Don't emit the enums here; they're already
+       in the `RootContext.typecontainer_resolve_order'.
+
+       * rootcontext.cs (RootContext.EmitCode): Don't emit the enums
+       here; they're already in the `typecontainer_resolve_order'.
+
+       * ecore.cs (EnumConstant.ConvertImplicitly): Add
+       TypeManager.DropGenericTypeArguments().
+
+       * typemanager.cs
+       (TypeManager.CSharpEnumValue): Add DropGenericTypeArguments().
+       (TypeManager.IsEnumType): Likewise.
+       (TypeManager.EnumToUnderlying): Likewise.
+       (TypeManager.IsEqual): Add support for enums.
+
 2007-03-12  Raja R Harinath  <rharinath@novell.com>
 
        * typemanager.cs (InitCoreTypes) [NET_2_0]: Allow
index 95f8ced910fe2aec98665e68c6a38703573e05fe..16a3bf5e926b0eeede4416a7a7d78c32b3e58a4b 100644 (file)
@@ -56,7 +56,8 @@ namespace Mono.CSharp {
                Root,
                Struct,
                Class,
-               Interface
+               Interface,
+               Enum
        }
 
        /// <summary>
@@ -1170,22 +1171,25 @@ namespace Mono.CSharp {
                bool DefineTypeBuilder ()
                {
                        try {
+                               Type default_parent = null;
+                               if (Kind == Kind.Struct)
+                                       default_parent = TypeManager.value_type;
+                               else if (Kind == Kind.Enum)
+                                       default_parent = TypeManager.enum_type;
+
                                if (IsTopLevel){
                                        if (TypeManager.NamespaceClash (Name, Location)) {
                                                return false;
                                        }
 
                                        ModuleBuilder builder = CodeGen.Module.Builder;
-                                       Type default_parent = null;
-                                       if (Kind == Kind.Struct)
-                                               default_parent = TypeManager.value_type;
                                        TypeBuilder = builder.DefineType (
                                                Name, TypeAttr, default_parent, null);
                                } else {
                                        TypeBuilder builder = Parent.TypeBuilder;
 
                                        TypeBuilder = builder.DefineNestedType (
-                                               Basename, TypeAttr, null, null);
+                                               Basename, TypeAttr, default_parent, null);
                                }
                        } catch (ArgumentException) {
                                Report.RuntimeMissingSupport (Location, "static classes");
@@ -2388,12 +2392,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (enums != null) {
-                               foreach (Enum e in enums) {
-                                       e.Emit ();
-                               }
-                       }
-
                        if (pending != null)
                                if (pending.VerifyPendingMethods ())
                                        return;
index 5da0b004f32c309b2eaff2478a3be1b2405b3bed..187d4fc2aa40b2ff3883c9832353edd5527b56fa 100644 (file)
@@ -24,7 +24,7 @@ namespace Mono.CSharp {
        }
 
        public class Const : FieldBase, IConstant {
-               Constant value;
+               protected Constant value;
                bool in_transit;
                bool define_called;
 
@@ -82,7 +82,7 @@ namespace Mono.CSharp {
                        //      return true;
 
                        while (ttype.IsArray)
-                           ttype = TypeManager.GetElementType (ttype);
+                               ttype = TypeManager.GetElementType (ttype);
 
                        FieldAttributes field_attr = FieldAttributes.Static | Modifiers.FieldAttr (ModFlags);
                        // Decimals cannot be emitted into the constant blob.  So, convert to 'readonly'.
@@ -180,27 +180,32 @@ namespace Mono.CSharp {
 
                        in_transit = true;
                        // TODO: IResolveContext here
-                       EmitContext ec = new EmitContext (this, Parent, Location, null, MemberType, ModFlags);
-                       value = initializer.ResolveAsConstant (ec, this);
+                       EmitContext ec = new EmitContext (
+                               this, Parent, Location, null, MemberType, ModFlags);
+                       ec.InEnumContext = this is EnumMember;
+                       value = DoResolveValue (ec);
                        in_transit = false;
+                       return value != null;
+               }
 
+               protected virtual Constant DoResolveValue (EmitContext ec)
+               {
+                       Constant value = initializer.ResolveAsConstant (ec, this);
                        if (value == null)
-                               return false;
+                               return null;
 
-                       Constant c  = value.ConvertImplicitly (MemberType);
+                       Constant c = value.ConvertImplicitly (MemberType);
                        if (c == null) {
                                if (!MemberType.IsValueType && MemberType != TypeManager.string_type && !value.IsDefaultValue)
                                        Error_ConstantCanBeInitializedWithNullOnly (Location, GetSignatureForError ());
                                else
                                        value.Error_ValueCannotBeConverted (null, Location, MemberType, false);
-                               return false;
                        }
 
-                       value = c;
-                       return true;
+                       return c;
                }
 
-               public Constant CreateConstantReference (Location loc)
+               public virtual Constant CreateConstantReference (Location loc)
                {
                        if (value == null)
                                return null;
index d4766671f98102b42684201152bd957d24be01ba..333eb186922d15e148cf1967db832845c49f9df7 100644 (file)
@@ -2504,8 +2504,9 @@ enum_declaration
 
                EnumMember em = null;
                foreach (VariableDeclaration ev in (ArrayList) $7) {
-                       em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
-                               new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
+                       em = new EnumMember (
+                               e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
+                               ev.OptAttributes, ev.Location);
 
 //                     if (RootContext.Documentation != null)
                                em.DocComment = ev.DocComment;
index 203837f2ef2afe5d07fc88bf54c4418f95aaa5be..c9959fa198cd5659db002068697c22abcbc0832e 100644 (file)
@@ -1567,12 +1567,16 @@ namespace Mono.CSharp {
 
                public override Constant ConvertImplicitly (Type type)
                {
-                       if (Type == type) {
+                       Type this_type = TypeManager.DropGenericTypeArguments (Type);
+                       type = TypeManager.DropGenericTypeArguments (type);
+
+                       if (this_type == type) {
                                // This is workaround of mono bug. It can be removed when the latest corlib spreads enough
                                if (TypeManager.IsEnumType (type.UnderlyingSystemType))
                                        return this;
 
-                               if (type.UnderlyingSystemType != Child.Type)
+                               Type child_type = TypeManager.DropGenericTypeArguments (Child.Type);
+                               if (type.UnderlyingSystemType != child_type)
                                        Child = Child.ConvertImplicitly (type.UnderlyingSystemType);
                                return this;
                        }
index a1a459a9daf9ee37ae1ebf480c1ecad5b1dc43d8..ae3158303bcc254af48240952d37eb6084f93f91 100644 (file)
@@ -19,55 +19,47 @@ using System.Globalization;
 
 namespace Mono.CSharp {
 
-       public class EnumMember : MemberCore, IConstant {
-               static string[] attribute_targets = new string [] { "field" };
-
-               public FieldBuilder builder;
-
-               readonly Enum parent_enum;
-               readonly Expression ValueExpr;
+       public class EnumMember : Const {
+               protected readonly Enum ParentEnum;
+               protected readonly Expression ValueExpr;
                readonly EnumMember prev_member;
 
-               EnumConstant value;
-               bool in_transit;
-
-               // TODO: remove or simplify
-               EmitContext ec;
-
-               public EnumMember (Enum parent_enum, EnumMember prev_member, Expression expr,
-                               MemberName name, Attributes attrs):
-                       base (parent_enum, name, attrs)
+               public EnumMember (Enum parent, EnumMember prev_member, string name, Expression expr,
+                                  Attributes attrs, Location loc)
+                       : base (parent, new EnumTypeExpr (parent), name, expr, Modifiers.PUBLIC,
+                               attrs, loc)
                {
-                       this.parent_enum = parent_enum;
-                       this.ModFlags = parent_enum.ModFlags;
+                       this.ParentEnum = parent;
                        this.ValueExpr = expr;
                        this.prev_member = prev_member;
-
-                       ec = new EmitContext (this, parent_enum, parent_enum, Location, null, null, ModFlags, false);
-                       ec.InEnumContext = true;
                }
 
-               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               protected class EnumTypeExpr : TypeExpr
                {
-                       if (a.Type == TypeManager.marshal_as_attr_type) {
-                               UnmanagedMarshal marshal = a.GetMarshal (this);
-                               if (marshal != null) {
-                                       builder.SetMarshal (marshal);
-                               }
-                               return;
+                       public readonly Enum Enum;
+
+                       public EnumTypeExpr (Enum e)
+                       {
+                               this.Enum = e;
                        }
 
-                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type)) {
-                               a.Error_InvalidSecurityParent ();
-                               return;
+                       protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
+                       {
+                               type = Enum.CurrentType != null ? Enum.CurrentType : Enum.TypeBuilder;
+                               return this;
                        }
 
-                       builder.SetCustomAttribute (cb);
-               }
+                       public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+                       {
+                               return DoResolveAsTypeStep (ec);
+                       }
 
-               public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Field;
+                       public override string Name {
+                               get { return Enum.Name; }
+                       }
+
+                       public override string FullName {
+                               get { return Enum.Name; }
                        }
                }
 
@@ -78,147 +70,58 @@ namespace Mono.CSharp {
                                t == TypeManager.ushort_type || t == TypeManager.uint64_type || t == TypeManager.char_type ||
                                t.IsEnum);
                }
-       
-               public override bool Define ()
-               {
-                       const FieldAttributes attr = FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal;
-                       TypeBuilder tb = parent_enum.TypeBuilder;
-                       builder = tb.DefineField (Name, tb, attr);
-                       ec.ContainerType = tb;
 
-                       TypeManager.RegisterConstant (builder, this);
-                       return true;
-               }
-
-               // Because parent is TypeContainer and we have DeclSpace only
-               public override void CheckObsoleteness (Location loc)
-               {
-                       parent_enum.CheckObsoleteness (loc);
-
-                       ObsoleteAttribute oa = GetObsoleteAttribute ();
-                       if (oa == null) {
-                               return;
-                       }
-
-                       AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
+               public object Value {
+                       get { return value.GetValue (); }
                }
-
-               public bool ResolveValue ()
+       
+               protected override Constant DoResolveValue (EmitContext ec)
                {
-                       if (value != null)
-                               return true;
-
-                       if (in_transit) {
-                               Const.Error_CyclicDeclaration (this);
-                               return false;
-                       }
-
                        if (ValueExpr != null) {
-                               in_transit = true;
                                Constant c = ValueExpr.ResolveAsConstant (ec, this);
-                               in_transit = false;
-
                                if (c == null)
-                                       return false;
+                                       return null;
 
                                if (c is EnumConstant)
                                        c = ((EnumConstant)c).Child;
-                                       
-                               c = c.ImplicitConversionRequired (parent_enum.UnderlyingType, Location);
+
+                               c = c.ImplicitConversionRequired (ParentEnum.UnderlyingType, Location);
                                if (c == null)
-                                       return false;
+                                       return null;
 
                                if (!IsValidEnumType (c.Type)) {
-                                       Report.Error (1008, Location, "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
-                                       return false;
+                                       Enum.Error_1008 (Location);
+                                       return null;
                                }
 
-                               in_transit = false;
-                               value = new EnumConstant (c, parent_enum.TypeBuilder);
-                               return true;
-                       }
-
-                       if (prev_member == null) {
-                               value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
-                               return true;
+                               return new EnumConstant (c, MemberType);
                        }
 
-                       if (!prev_member.ResolveValue ()) {
-                               // Suppress cyclic error
-                               prev_member.value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
-                               return false;
+                       if ((prev_member == null) || (prev_member.value == null)) {
+                               return new EnumConstant (
+                                       New.Constantify (ParentEnum.UnderlyingType), MemberType);
                        }
 
-                       in_transit = true;
-
                        try {
-                               value = (EnumConstant)prev_member.value.Increment ();
-                       }
-                       catch (OverflowException) {
-                               Report.Error (543, Location, "The enumerator value `{0}' is too large to fit in its type `{1}'",
-                                       GetSignatureForError (), TypeManager.CSharpName (parent_enum.UnderlyingType));
-                               return false;
-                       }
-                       in_transit = false;
-
-                       return true;
-               }
-
-               public override void Emit ()
-               {
-                       if (OptAttributes != null)
-                               OptAttributes.Emit (); 
-
-                       if (!ResolveValue ()) {
-                               // Suppress cyclic errors
-                               value = new EnumConstant(New.Constantify(parent_enum.UnderlyingType), parent_enum.TypeBuilder);
-                               return;
-                       }
-
-                       builder.SetConstant (value.GetValue ());
-                       base.Emit ();
-               }
-
-               public override string GetSignatureForError()
-               {
-                       return String.Concat (parent_enum.GetSignatureForError (), '.', Name);
-               }
-
-               public override string[] ValidAttributeTargets {
-                       get {
-                               return attribute_targets;
-                       }
-               }
-
-               public override string DocCommentHeader {
-                       get { return "F:"; }
-               }
-
-               public object Value { get { return value.GetValue (); } }
-
-               #region IConstant Members
-
-               public Constant CreateConstantReference (Location loc)
-               {
-                       if (value == null)
+                               return (EnumConstant) prev_member.value.Increment ();
+                       } catch (OverflowException) {
+                               Report.Error (543, Location, "The enumerator value `{0}' is too " +
+                                             "large to fit in its type `{1}'", GetSignatureForError (),
+                                             TypeManager.CSharpName (ParentEnum.UnderlyingType));
                                return null;
-
-                       return new EnumConstant (Constant.CreateConstant (value.Child.Type, value.Child.GetValue(), loc),
-                               value.Type);
+                       }
                }
-
-               #endregion
        }
 
        /// <summary>
        ///   Enumeration container
        /// </summary>
-       public class Enum : DeclSpace {
-               Expression BaseType;
+       public class Enum : TypeContainer
+       {
+               Expression base_type;
+
                public Type UnderlyingType;
 
-               static MemberList no_list = new MemberList (new object[0]);
-               
                public const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -228,36 +131,41 @@ namespace Mono.CSharp {
 
                public Enum (NamespaceEntry ns, DeclSpace parent, Expression type,
                             int mod_flags, MemberName name, Attributes attrs)
-                       : base (ns, parent, name, attrs)
+                       : base (ns, parent, name, attrs, Kind.Enum)
                {
-                       this.BaseType = type;
-                       ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
-                                                   IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE, name.Location);
+                       this.base_type = type;
+                       int accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
+                       ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, accmods, Location);
                }
 
                public void AddEnumMember (EnumMember em)
                {
                        if (em.Name == "value__") {
-                               Report.Error (76, em.Location, "An item in an enumeration cannot have an identifier `value__'");
+                               Report.Error (76, em.Location, "An item in an enumeration cannot " +
+                                             "have an identifier `value__'");
                                return;
                        }
 
-                       if (!AddToContainer (em, em.Name))
-                               return;
+                       AddConstant (em);
+               }
+
+               public static void Error_1008 (Location loc)
+               {
+                       Report.Error (1008, loc, "Type byte, sbyte, short, ushort, " +
+                                     "int, uint, long or ulong expected");
                }
-               
-               public override TypeBuilder DefineType ()
+
+               protected override bool DefineNestedTypes ()
                {
-                       if (TypeBuilder != null)
-                               return TypeBuilder;
+                       if (!base.DefineNestedTypes ())
+                               return false;
 
-                       if (!(BaseType is TypeLookupExpression)) {
-                               Report.Error (1008, Location,
-                                       "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
-                               return null;
+                       if (!(base_type is TypeLookupExpression)) {
+                               Error_1008 (Location);
+                               return false;
                        }
 
-                       TypeExpr ute = BaseType.ResolveAsTypeTerminal (this, false);
+                       TypeExpr ute = base_type.ResolveAsTypeTerminal (this, false);
                        UnderlyingType = ute.Type;
 
                        if (UnderlyingType != TypeManager.int32_type &&
@@ -268,23 +176,8 @@ namespace Mono.CSharp {
                            UnderlyingType != TypeManager.ushort_type &&
                            UnderlyingType != TypeManager.byte_type  &&
                            UnderlyingType != TypeManager.sbyte_type) {
-                               Report.Error (1008, Location,
-                                       "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
-                               return null;
-                       }
-
-                       if (IsTopLevel) {
-                               if (TypeManager.NamespaceClash (Name, Location))
-                                       return null;
-                               
-                               ModuleBuilder builder = CodeGen.Module.Builder;
-
-                               TypeBuilder = builder.DefineType (Name, TypeAttr, TypeManager.enum_type);
-                       } else {
-                               TypeBuilder builder = Parent.TypeBuilder;
-
-                               TypeBuilder = builder.DefineNestedType (
-                                       Basename, TypeAttr, TypeManager.enum_type);
+                               Error_1008 (Location);
+                               return false;
                        }
 
                        //
@@ -294,51 +187,9 @@ namespace Mono.CSharp {
                                                 FieldAttributes.Public | FieldAttributes.SpecialName
                                                 | FieldAttributes.RTSpecialName);
 
-                       TypeManager.AddUserType (this);
-
-                       foreach (EnumMember em in defined_names.Values) {
-                               if (!em.Define ())
-                                       return null;
-                       }
-
-                       return TypeBuilder;
-               }
-               
-               public override bool Define ()
-               {
                        return true;
                }
 
-               public override void Emit ()
-               {
-                       if (OptAttributes != null) {
-                               OptAttributes.Emit ();
-                       }
-
-                       foreach (EnumMember em in defined_names.Values) {
-                               em.Emit ();
-                       }
-
-                       base.Emit ();
-               }
-
-               //
-               // IMemberFinder
-               //
-               public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
-                       MemberFilter filter, object criteria)
-               {
-                       if ((mt & MemberTypes.Field) == 0)
-                               return no_list;
-
-                       EnumMember em = defined_names [criteria] as EnumMember;
-                       if (em == null)
-                               return no_list;
-
-                       FieldBuilder[] fb = new FieldBuilder[] { em.builder };
-                       return new MemberList (fb);
-               }
-
                //
                // Used for error reporting only
                //
@@ -352,36 +203,11 @@ namespace Mono.CSharp {
                        throw new ArgumentOutOfRangeException (value.ToString ());
                }
 
-               
-               void VerifyClsName ()
-               {
-                       HybridDictionary dict = new HybridDictionary (defined_names.Count, true);
-                       foreach (EnumMember em in defined_names.Values) {
-                               if (!em.IsClsComplianceRequired ())
-                                       continue;
-
-                               try {
-                                       dict.Add (em.Name, em);
-                               }
-                               catch (ArgumentException) {
-                                       Report.SymbolRelatedToPreviousError (em);
-                                       MemberCore col = (MemberCore)dict [em.Name];
-#if GMCS_SOURCE
-                                       Report.Warning (3005, 1, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
-#else
-                                       Report.Error (3005, col.Location, "Identifier `{0}' differing only in case is not CLS-compliant", col.GetSignatureForError ());
-#endif
-                               }
-                       }
-               }
-
                protected override bool VerifyClsCompliance ()
                {
                        if (!base.VerifyClsCompliance ())
                                return false;
 
-                       VerifyClsName ();
-
                        if (UnderlyingType == TypeManager.uint32_type ||
                                UnderlyingType == TypeManager.uint64_type ||
                                UnderlyingType == TypeManager.ushort_type) {
@@ -389,14 +215,7 @@ namespace Mono.CSharp {
                        }
 
                        return true;
-               }
-       
-
-               public override MemberCache MemberCache {
-                       get {
-                               return null;
-                       }
-               }
+               }       
 
                public override AttributeTargets AttributeTargets {
                        get {
@@ -407,29 +226,8 @@ namespace Mono.CSharp {
                protected override TypeAttributes TypeAttr {
                        get {
                                return Modifiers.TypeAttr (ModFlags, IsTopLevel) |
-                               TypeAttributes.Class | TypeAttributes.Sealed |
-                               base.TypeAttr;
-                       }
-               }
-
-               //
-               // Generates xml doc comments (if any), and if required,
-               // handle warning report.
-               //
-               internal override void GenerateDocComment (DeclSpace ds)
-               {
-                       base.GenerateDocComment (ds);
-
-                       foreach (EnumMember em in defined_names.Values) {
-                               em.GenerateDocComment (this);
+                                       TypeAttributes.Class | TypeAttributes.Sealed | base.TypeAttr;
                        }
                }
-
-               //
-               //   Represents header string for documentation comment.
-               //
-               public override string DocCommentHeader {
-                       get { return "T:"; }
-               }
        }
 }
index 07e3d3afd37e032e5a1fcf3745419fa166219ba0..342699fa23de73144dfd14eb1003b62510e3fec5 100644 (file)
@@ -606,11 +606,6 @@ namespace Mono.CSharp {
 
                static public void EmitCode ()
                {
-                       if (root.Enums != null) {
-                               foreach (Enum e in root.Enums)
-                                       e.Emit ();
-                       }
-
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
                                        tc.EmitType ();
index 7f5560acc06ca88f902e8c01ed0a1c794c3fff31..0deeb48c9b1107f10690ec130cc6112ec550fe40 100644 (file)
@@ -3017,7 +3017,7 @@ namespace Mono.CSharp {
                //
                Expression SwitchGoverningType (EmitContext ec, Expression expr)
                {
-                       Type t = expr.Type;
+                       Type t = TypeManager.DropGenericTypeArguments (expr.Type);
 
                        if (t == TypeManager.byte_type ||
                            t == TypeManager.sbyte_type ||
index 91f8b52464fdad6dcca6d54ec8cd0a499cac7dd5..704b20f480e879dda23b8e3bc685d0c285074322 100644 (file)
@@ -663,6 +663,7 @@ namespace Mono.CSharp {
        // Used for error reporting to show symbolic name instead of underlying value
        public static string CSharpEnumValue (Type t, object value)
        {
+               t = DropGenericTypeArguments (t);
                Enum e = LookupDeclSpace (t) as Enum;
                if (e == null)
                        return System.Enum.GetName (t, value);
@@ -1586,6 +1587,7 @@ namespace Mono.CSharp {
        
        public static bool IsEnumType (Type t)
        {
+               t = DropGenericTypeArguments (t);
                if (builder_to_declspace [t] is Enum)
                        return true;
 
@@ -2359,6 +2361,7 @@ namespace Mono.CSharp {
        //
        public static Type EnumToUnderlying (Type t)
        {
+               t = DropGenericTypeArguments (t);
                if (t == TypeManager.enum_type)
                        return t;
 
@@ -2763,9 +2766,15 @@ namespace Mono.CSharp {
                        return IsEqual (a.GetElementType (), b.GetElementType ());
 
                if (a.IsGenericType && b.IsGenericType) {
-                       if (a.GetGenericTypeDefinition () != b.GetGenericTypeDefinition ())
+                       Type adef = a.GetGenericTypeDefinition ();
+                       Type bdef = b.GetGenericTypeDefinition ();
+
+                       if (adef != bdef)
                                return false;
 
+                       if (adef.IsEnum && bdef.IsEnum)
+                               return true;
+
                        Type[] aargs = a.GetGenericArguments ();
                        Type[] bargs = b.GetGenericArguments ();
 
diff --git a/mcs/tests/gtest-313.cs b/mcs/tests/gtest-313.cs
new file mode 100755 (executable)
index 0000000..8ffb85f
--- /dev/null
@@ -0,0 +1,25 @@
+using System;
+
+class Foo<T>
+{
+       public enum TestEnum { One, Two, Three }
+
+       public TestEnum Test;
+
+       public Foo (TestEnum test)
+       {
+               this.Test = test;
+       }
+}
+
+class X
+{
+       static void Main ()
+       {
+               Foo<int>.TestEnum e = Foo<int>.TestEnum.One;
+               Console.WriteLine (e);
+
+               Foo<int> foo = new Foo<int> (e);
+               foo.Test = e;
+       }
+}