* XmlTypeAttribute.cs: added property AnonymousType for 2.0
[mono.git] / mcs / mcs / const.cs
index e883b7e4eaf82c97908491e29d1a0b4ac8b79762..ef9f2b2888ff27247d642f8d54faa7ed9e89e7f7 100644 (file)
@@ -34,7 +34,7 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public Const (TypeContainer parent, Expression constant_type, string name,
+               public Const (DeclSpace parent, Expression constant_type, string name,
                              Expression expr, int mod_flags, Attributes attrs, Location loc)
                        : base (parent, constant_type, mod_flags, AllowedModifiers,
                                new MemberName (name, loc), attrs)
@@ -48,7 +48,7 @@ namespace Mono.CSharp {
                        // Constant.Define can be called when the parent type hasn't yet been populated
                        // and it's base types need not have been populated.  So, we defer this check
                        // to the second time Define () is called on this member.
-                       if (ParentContainer.BaseCache == null)
+                       if (Parent.PartialContainer.BaseCache == null)
                                return true;
                        return base.CheckBase ();
                }
@@ -73,9 +73,8 @@ namespace Mono.CSharp {
                        // Decimals cannot be emitted into the constant blob.  So, convert to 'readonly'.
                        if (ttype == TypeManager.decimal_type) {
                                field_attr |= FieldAttributes.InitOnly;
-                               ParentContainer.RegisterFieldForInitialization (this);
-                       }
-                       else {
+                               Parent.PartialContainer.RegisterFieldForInitialization (this);
+                       } else {
                                field_attr |= FieldAttributes.Literal;
                        }
 
@@ -108,8 +107,13 @@ namespace Mono.CSharp {
                        base.Emit ();
                }
 
-               public static void Error_ExpressionMustBeConstant (Location loc, string e_name)
+               public static void Error_ExpressionMustBeConstant (Type constantType, Location loc, string e_name)
                {
+                       if (constantType != null && TypeManager.IsValueType (constantType) &&
+                               !TypeManager.IsBuiltinOrEnum (constantType)) {
+                               Report.Error (283, loc, "The type `{0}' cannot be declared const", TypeManager.CSharpName (constantType));
+                               return;
+                       }
                        Report.Error (133, loc, "The expression being assigned to `{0}' must be constant", e_name);
                }
 
@@ -119,6 +123,12 @@ namespace Mono.CSharp {
                                mc.GetSignatureForError ());
                }
 
+               public static void Error_ConstantCanBeInitializedWithNullOnly (Location loc, string name)
+               {
+                       Report.Error (134, loc, "`{0}': the constant of reference type other than string can only be initialized with null",
+                               name);
+               }
+
                #region IConstant Members
 
                public bool ResolveValue ()
@@ -148,8 +158,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (!MemberType.IsValueType && MemberType != TypeManager.string_type && !value.IsDefaultValue) {
-                               Report.Error (134, Location, "`{0}': A const of reference other than string can only be initialized with null",
-                                       GetSignatureForError ());
+                               Error_ConstantCanBeInitializedWithNullOnly (Location, GetSignatureForError ());
                                return false;
                        }