make line-endings uniform
[mono.git] / mcs / mcs / enum.cs
index c479d985984322805120cfb2f4fcc4fb2de76a11..f01f2654b8c16b8256d15c04dc7989cb80eba611 100644 (file)
@@ -28,7 +28,7 @@ namespace Mono.CSharp {
                readonly Expression ValueExpr;
                readonly EnumMember prev_member;
 
-               Constant value;
+               EnumConstant value;
                bool in_transit;
 
                // TODO: remove or simplify
@@ -71,7 +71,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               bool IsValidEnumType (Type t)
+               static bool IsValidEnumType (Type t)
                {
                        return (t == TypeManager.int32_type || t == TypeManager.uint32_type || t == TypeManager.int64_type ||
                                t == TypeManager.byte_type || t == TypeManager.sbyte_type || t == TypeManager.short_type ||
@@ -109,8 +109,6 @@ namespace Mono.CSharp {
                                return true;
 
                        if (in_transit) {
-                               // suppress cyclic errors
-                               value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
                                Const.Error_CyclicDeclaration (this);
                                return false;
                        }
@@ -126,7 +124,7 @@ namespace Mono.CSharp {
                                if (c is EnumConstant)
                                        c = ((EnumConstant)c).Child;
                                        
-                               c = c.ToType (parent_enum.UnderlyingType, Location);
+                               c = c.ImplicitConversionRequired (parent_enum.UnderlyingType, Location);
                                if (c == null)
                                        return false;
 
@@ -145,13 +143,16 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       if (!prev_member.ResolveValue ())
+                       if (!prev_member.ResolveValue ()) {
+                               // Suppress cyclic error
+                               prev_member.value = new EnumConstant (New.Constantify (parent_enum.UnderlyingType), parent_enum.TypeBuilder);
                                return false;
+                       }
 
                        in_transit = true;
 
                        try {
-                               value = prev_member.value.Increment ();
+                               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}'",
@@ -168,8 +169,11 @@ namespace Mono.CSharp {
                        if (OptAttributes != null)
                                OptAttributes.Emit (); 
 
-                       if (!ResolveValue ())
+                       if (!ResolveValue ()) {
+                               // Suppress cyclic errors
+                               value = new EnumConstant(New.Constantify(parent_enum.UnderlyingType), parent_enum.TypeBuilder);
                                return;
+                       }
 
                        builder.SetConstant (value.GetValue ());
                        base.Emit ();
@@ -192,10 +196,13 @@ namespace Mono.CSharp {
 
                #region IConstant Members
 
-               public Constant Value {
-                       get {
-                               return value;
-                       }
+               public Constant CreateConstantReference (Location loc)
+               {
+                       if (value == null)
+                               return null;
+
+                       return new EnumConstant (Constant.CreateConstant (value.Child.Type, value.Child.GetValue(), loc),
+                               value.Type);
                }
 
                #endregion
@@ -343,7 +350,11 @@ namespace Mono.CSharp {
                                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
                                }
                        }
                }