//
public static EmitContext ConstantEC = null;
- static void Error_CannotConvertType (Location loc, Type source, Type target)
+ static public void Error_CannotConvertType (Location loc, Type source, Type target)
{
Report.Error (30, loc, "Cannot convert type '" +
TypeManager.CSharpName (source) + "' to '" +
static bool TypeParameter_to_Null (Type target_type)
{
- if ((target_type.BaseType == null) ||
- (target_type.BaseType == TypeManager.value_type) ||
- target_type.BaseType.IsValueType)
+ GenericConstraints gc = TypeManager.GetTypeParameterConstraints (target_type);
+ if (gc == null)
return false;
- return true;
+ if (gc.HasReferenceTypeConstraint)
+ return true;
+ if (gc.HasClassConstraint && !TypeManager.IsValueType (gc.ClassConstraint))
+ return true;
+
+ return false;
}
static Type TypeParam_EffectiveBaseType (EmitContext ec, Type t)
if (TypeManager.IsValueType (expr_type))
return new BoxedCast (expr);
if (expr_type.IsClass || expr_type.IsInterface || expr_type == TypeManager.enum_type){
- if (target_type == TypeManager.anonymous_method_type)
+ if (expr_type == TypeManager.anonymous_method_type)
return null;
return new EmptyCast (expr, target_type);
}
//
// Possibly, we need to create a different 0 literal before passing
// to EnumConstant
- //n
+ //
if (underlying == TypeManager.int64_type)
e = new LongLiteral (0);
else if (underlying == TypeManager.uint64_type)
static public void Error_CannotImplicitConversion (Location loc, Type source, Type target)
{
+ if (source.Name == target.Name){
+ Report.ExtraInformation (loc,
+ String.Format (
+ "The type {0} has two conflicting definitons, one comes from {0} and the other from {1}",
+ source.Assembly.FullName, target.Assembly.FullName));
+
+ }
Report.Error (29, loc, "Cannot convert implicitly from {0} to `{1}'",
source == TypeManager.anonymous_method_type ?
"anonymous method" : "`" + TypeManager.CSharpName (source) + "'",
if (e != null)
return e;
- if (source is DoubleLiteral && target_type == TypeManager.float_type){
- Report.Error (664, loc,
- "Double literal cannot be implicitly converted to " +
- "float type, use F suffix to create a float literal");
+ if (source is DoubleLiteral) {
+ if (target_type == TypeManager.float_type) {
+ Error_664 (loc, "float", "f");
+ return null;
+ }
+ if (target_type == TypeManager.decimal_type) {
+ Error_664 (loc, "decimal", "m");
+ return null;
+ }
}
if (source is Constant){
return null;
}
+ static void Error_664 (Location loc, string type, string suffix) {
+ Report.Error (664, loc,
+ "Literal of type double cannot be implicitly converted to type '{0}'. Add suffix '{1}' to create a literal of this type",
+ type, suffix);
+ }
+
/// <summary>
/// Performs the explicit numeric conversions
/// </summary>