Fix unmanaged type check for nested generic types
[mono.git] / mcs / mcs / enum.cs
index c71235b77da05315485b991c489eac33d4c1a82c..4b0f4a020432e8691595e31a69658726ba7def7b 100644 (file)
@@ -27,15 +27,11 @@ namespace Mono.CSharp {
        {
                class EnumTypeExpr : TypeExpr
                {
-                       protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
+                       public override TypeSpec ResolveAsType (IMemberContext ec)
                        {
                                type = ec.CurrentType;
-                               return this;
-                       }
-
-                       public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
-                       {
-                               return DoResolveAsTypeStep (ec);
+                               eclass = ExprClass.Type;
+                               return type;
                        }
                }
 
@@ -46,16 +42,16 @@ namespace Mono.CSharp {
 
                static bool IsValidEnumType (TypeSpec t)
                {
-                       switch (t.BuildinType) {
-                       case BuildinTypeSpec.Type.Int:
-                       case BuildinTypeSpec.Type.UInt:
-                       case BuildinTypeSpec.Type.Long:
-                       case BuildinTypeSpec.Type.Byte:
-                       case BuildinTypeSpec.Type.SByte:
-                       case BuildinTypeSpec.Type.Short:
-                       case BuildinTypeSpec.Type.UShort:
-                       case BuildinTypeSpec.Type.ULong:
-                       case BuildinTypeSpec.Type.Char:
+                       switch (t.BuiltinType) {
+                       case BuiltinTypeSpec.Type.Int:
+                       case BuiltinTypeSpec.Type.UInt:
+                       case BuiltinTypeSpec.Type.Long:
+                       case BuiltinTypeSpec.Type.Byte:
+                       case BuiltinTypeSpec.Type.SByte:
+                       case BuiltinTypeSpec.Type.Short:
+                       case BuiltinTypeSpec.Type.UShort:
+                       case BuiltinTypeSpec.Type.ULong:
+                       case BuiltinTypeSpec.Type.Char:
                                return true;
                        default:
                                return t.IsEnum;
@@ -79,7 +75,7 @@ namespace Mono.CSharp {
                        if (expr == null)
                                expr = New.Constantify (underlying, Location);
 
-                       return new EnumConstant (expr, MemberType).Resolve (rc);
+                       return new EnumConstant (expr, MemberType);
                }
 
                public override bool Define ()
@@ -104,7 +100,7 @@ namespace Mono.CSharp {
                //
                // Implicit enum member initializer, used when no constant value is provided
                //
-               class ImplicitInitializer : Expression
+               sealed class ImplicitInitializer : Expression
                {
                        readonly EnumMember prev;
                        readonly EnumMember current;
@@ -115,6 +111,11 @@ namespace Mono.CSharp {
                                this.prev = prev;
                        }
 
+                       public override bool ContainsEmitWithAwait ()
+                       {
+                               return false;
+                       }
+
                        public override Expression CreateExpressionTree (ResolveContext ec)
                        {
                                throw new NotSupportedException ("Missing Resolve call");
@@ -124,18 +125,18 @@ namespace Mono.CSharp {
                        {
                                // We are the first member
                                if (prev == null) {
-                                       return New.Constantify (current.Parent.Definition, Location).Resolve (rc);
+                                       return New.Constantify (current.Parent.Definition, Location);
                                }
 
                                var c = ((ConstSpec) prev.Spec).GetConstant (rc) as EnumConstant;
                                try {
-                                       return c.Increment ().Resolve (rc);
+                                       return c.Increment ();
                                } catch (OverflowException) {
                                        rc.Report.Error (543, current.Location,
                                                "The enumerator value `{0}' is outside the range of enumerator underlying type `{1}'",
                                                current.GetSignatureForError (), ((Enum) current.Parent).UnderlyingType.GetSignatureForError ());
 
-                                       return New.Constantify (current.Parent.Definition, current.Location).Resolve (rc);
+                                       return New.Constantify (current.Parent.Definition, current.Location);
                                }
                        }
 
@@ -154,11 +155,13 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpression type,
+               readonly TypeExpr underlying_type_expr;
+
+               public Enum (NamespaceContainer ns, DeclSpace parent, TypeExpression type,
                             Modifiers mod_flags, MemberName name, Attributes attrs)
                        : base (ns, parent, name, attrs, MemberKind.Enum)
                {
-                       base_type_expr = type;
+                       underlying_type_expr = type;
                        var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
                        ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod_flags, accmods, Location, Report);
                        spec = new EnumSpec (null, this, null, null, ModFlags);
@@ -174,7 +177,7 @@ namespace Mono.CSharp {
 
                public TypeExpr BaseTypeExpression {
                        get {
-                               return base_type_expr;
+                               return underlying_type_expr;
                        }
                }
 
@@ -217,7 +220,7 @@ namespace Mono.CSharp {
 
                protected override bool DefineNestedTypes ()
                {
-                       ((EnumSpec) spec).UnderlyingType = base_type_expr == null ? TypeManager.int32_type : base_type_expr.Type;
+                       ((EnumSpec) spec).UnderlyingType = underlying_type_expr == null ? Compiler.BuiltinTypes.Int : underlying_type_expr.Type;
 
                        TypeBuilder.DefineField (UnderlyingValueField, UnderlyingType.GetMetaInfo (),
                                FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
@@ -246,10 +249,10 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
+               protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
                {
-                       base_type = Compiler.BuildinTypes.Enum;
-                       base_class = base_type_expr;
+                       base_type = Compiler.BuiltinTypes.Enum;
+                       base_class = null;
                        return null;
                }
 
@@ -258,10 +261,10 @@ namespace Mono.CSharp {
                        if (!base.VerifyClsCompliance ())
                                return false;
 
-                       switch (UnderlyingType.BuildinType) {
-                       case BuildinTypeSpec.Type.UInt:
-                       case BuildinTypeSpec.Type.ULong:
-                       case BuildinTypeSpec.Type.UShort:
+                       switch (UnderlyingType.BuiltinType) {
+                       case BuiltinTypeSpec.Type.UInt:
+                       case BuiltinTypeSpec.Type.ULong:
+                       case BuiltinTypeSpec.Type.UShort:
                                Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant",
                                        GetSignatureForError (), TypeManager.CSharpName (UnderlyingType));
                                break;
@@ -300,15 +303,15 @@ namespace Mono.CSharp {
 
                public static bool IsValidUnderlyingType (TypeSpec type)
                {
-                       switch (type.BuildinType) {
-                       case BuildinTypeSpec.Type.Int:
-                       case BuildinTypeSpec.Type.UInt:
-                       case BuildinTypeSpec.Type.Long:
-                       case BuildinTypeSpec.Type.Byte:
-                       case BuildinTypeSpec.Type.SByte:
-                       case BuildinTypeSpec.Type.Short:
-                       case BuildinTypeSpec.Type.UShort:
-                       case BuildinTypeSpec.Type.ULong:
+                       switch (type.BuiltinType) {
+                       case BuiltinTypeSpec.Type.Int:
+                       case BuiltinTypeSpec.Type.UInt:
+                       case BuiltinTypeSpec.Type.Long:
+                       case BuiltinTypeSpec.Type.Byte:
+                       case BuiltinTypeSpec.Type.SByte:
+                       case BuiltinTypeSpec.Type.Short:
+                       case BuiltinTypeSpec.Type.UShort:
+                       case BuiltinTypeSpec.Type.ULong:
                                return true;
                        }