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)
// 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 ();
}
// 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;
}
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);
}
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 ()
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;
}