if (expr_type == target_type)
return true;
+
// First numeric conversions
if (expr_type == TypeManager.sbyte_type){
return true;
}
+ if (expr.eclass == ExprClass.MethodGroup){
+ if (TypeManager.IsDelegateType (target_type) && RootContext.Version != LanguageVersion.ISO_1){
+ MethodGroupExpr mg = expr as MethodGroupExpr;
+ if (mg != null){
+ //
+ // This should not happen frequently, so we can create an object
+ // to test compatibility
+ //
+ Expression c = ImplicitDelegateCreation.Create (ec, mg, target_type, Location.Null);
+ return c != null;
+ }
+ }
+ }
+
if (ImplicitReferenceConversionExists (expr, target_type))
return true;
return true;
}
+ //
+ // If `expr_type' implements `target_type' (which is an iface)
+ // see TryImplicitIntConversion
+ //
+ if (target_type.IsInterface && target_type.IsAssignableFrom (expr_type))
+ return true;
+
if (target_type == TypeManager.void_ptr_type && expr_type.IsPointer)
return true;
return false;
AnonymousMethod am = (AnonymousMethod) expr;
- int errors = Report.Errors;
Expression conv = am.Compatible (ec, target_type, true);
if (conv != null)
return true;
}
-
+
return false;
}
//
Type source_type = source.Type;
foreach (MethodBase mb in me.Methods){
- ParameterData pd = Invocation.GetParameterData (mb);
+ ParameterData pd = TypeManager.GetParameterData (mb);
Type param_type = pd.ParameterType (0);
if (param_type == source_type)
foreach (MethodBase mb in union.Methods){
- ParameterData pd = Invocation.GetParameterData (mb);
+ ParameterData pd = TypeManager.GetParameterData (mb);
MethodInfo mi = (MethodInfo) mb;
if (pd.ParameterType (0) == most_specific_source &&
}
/// <summary>
- /// Attemps to perform an implict constant conversion of the IntConstant
+ /// Attempts to perform an implicit constant conversion of the IntConstant
/// into a different data type using casts (See Implicit Constant
/// Expression Conversions)
/// </summary>
return new EnumConstant (e, target_type);
}
+
+ //
+ // If `target_type' is an interface and the type of `ic' implements the interface
+ // e.g. target_type is IComparable, IConvertible, IFormattable
+ //
+ if (target_type.IsInterface && target_type.IsAssignableFrom (ic.Type))
+ return new BoxedCast (ic);
+
return null;
}
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) + "'",
}
/// <summary>
- /// Attemptes to implicityly convert `target' into `type', using
+ /// Attempts to implicitly convert `source' into `target_type', using
/// ImplicitConversion. If there is no implicit conversion, then
/// an error is signaled
/// </summary>