Merge pull request #3609 from xmcclure/checked-imageset
[mono.git] / mcs / mcs / enum.cs
index 847a98d87e32136ced4968f13dd800729e62f932..3e1c3fc653091cd47f86df6b839d92c96a296127 100644 (file)
@@ -28,7 +28,7 @@ namespace Mono.CSharp {
        {
                class EnumTypeExpr : TypeExpr
                {
-                       public override TypeSpec ResolveAsType (IMemberContext ec)
+                       public override TypeSpec ResolveAsType (IMemberContext ec, bool allowUnboundTypeArguments)
                        {
                                type = ec.CurrentType;
                                eclass = ExprClass.Type;
@@ -64,11 +64,12 @@ namespace Mono.CSharp {
                        if (expr is EnumConstant)
                                expr = ((EnumConstant) expr).Child;
 
-                       var underlying = ((Enum) Parent).UnderlyingType;
+                       var en = (Enum)Parent;
+                       var underlying = en.UnderlyingType;
                        if (expr != null) {
-                               expr = expr.ImplicitConversionRequired (rc, underlying, Location);
+                               expr = expr.ImplicitConversionRequired (rc, underlying);
                                if (expr != null && !IsValidEnumType (expr.Type)) {
-                                       Enum.Error_1008 (Location, Report);
+                                       en.Error_UnderlyingType (Location);
                                        expr = null;
                                }
                        }
@@ -162,9 +163,9 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               readonly TypeExpr underlying_type_expr;
+               readonly FullNamedExpression underlying_type_expr;
 
-               public Enum (TypeContainer parent, TypeExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+               public Enum (TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
                        : base (parent, name, attrs, MemberKind.Enum)
                {
                        underlying_type_expr = type;
@@ -181,7 +182,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public TypeExpr BaseTypeExpression {
+               public FullNamedExpression BaseTypeExpression {
                        get {
                                return underlying_type_expr;
                        }
@@ -217,7 +218,7 @@ namespace Mono.CSharp {
                        AddMember (em);
                }
 
-               public static void Error_1008 (Location loc, Report Report)
+               public void Error_UnderlyingType (Location loc)
                {
                        Report.Error (1008, loc,
                                "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
@@ -225,7 +226,21 @@ namespace Mono.CSharp {
 
                protected override void DoDefineContainer ()
                {
-                       ((EnumSpec) spec).UnderlyingType = underlying_type_expr == null ? Compiler.BuiltinTypes.Int : underlying_type_expr.Type;
+                       TypeSpec ut;
+                       if (underlying_type_expr != null) {
+                               ut = underlying_type_expr.ResolveAsType (this);
+                               if (!EnumSpec.IsValidUnderlyingType (ut)) {
+                                       Error_UnderlyingType (underlying_type_expr.Location);
+                                       ut = null;
+                               }
+                       } else {
+                               ut = null;
+                       }
+
+                       if (ut == null)
+                               ut = Compiler.BuiltinTypes.Int;
+
+                       ((EnumSpec) spec).UnderlyingType = ut;
 
                        TypeBuilder.DefineField (UnderlyingValueField, UnderlyingType.GetMetaInfo (),
                                FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
@@ -269,7 +284,7 @@ namespace Mono.CSharp {
                        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));
+                                       GetSignatureForError (), UnderlyingType.GetSignatureForError ());
                                break;
                        }