Constant CreateConstantReference (Location loc);
}
- public class Const : FieldMember, IConstant {
+ public class Const : FieldBase, IConstant {
Constant value;
bool in_transit;
bool define_called;
// Decimals cannot be emitted into the constant blob. So, convert to 'readonly'.
if (ttype == TypeManager.decimal_type) {
field_attr |= FieldAttributes.InitOnly;
- Parent.PartialContainer.RegisterFieldForInitialization (this);
} else {
field_attr |= FieldAttributes.Literal;
}
FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType, field_attr);
-
TypeManager.RegisterConstant (FieldBuilder, this);
+ if (ttype == TypeManager.decimal_type)
+ Parent.PartialContainer.RegisterFieldForInitialization (this, new FieldInitializer (FieldBuilder, initializer));
+
return true;
}
if (value == null)
return false;
- value = value.ImplicitConversionRequired (MemberType, Location);
- if (value == null)
- return false;
-
- if (!MemberType.IsValueType && MemberType != TypeManager.string_type && !value.IsDefaultValue) {
- Error_ConstantCanBeInitializedWithNullOnly (Location, GetSignatureForError ());
+ Constant c = value.ConvertImplicitly (MemberType);
+ if (c == null) {
+ if (!MemberType.IsValueType && MemberType != TypeManager.string_type && !value.IsDefaultValue)
+ Error_ConstantCanBeInitializedWithNullOnly (Location, GetSignatureForError ());
+ else
+ value.Error_ValueCannotBeConverted (null, Location, MemberType, false);
return false;
}
+ value = c;
return true;
}