if (TypeManager.IsValueType (expr_type))
return new BoxedCast (expr);
if (expr is NullLiteral)
- return new BoxedCast (expr);
+ return new NullCast (expr, target_type);
} else if (expr_type.IsSubclassOf (target_type)) {
//
// Special case: enumeration to System.Enum.
static public Expression ImplicitConversion (EmitContext ec, Expression expr,
Type target_type, Location loc)
{
- Type expr_type = expr.Type;
Expression e;
if (target_type == null)
Type expr_type = expr.Type;
Expression e;
+ if (expr.eclass == ExprClass.MethodGroup){
+ if (!TypeManager.IsDelegateType (target_type)){
+ Report.Error (428, loc,
+ String.Format (
+ "Cannot convert method group to `{0}', since it is not a delegate",
+ TypeManager.CSharpName (target_type)));
+ return null;
+ }
+
+ return ImplicitDelegateCreation.Create (ec, (MethodGroupExpr) expr, target_type, loc);
+ }
+
if (expr_type.Equals (target_type) && !(expr is NullLiteral))
return expr;
if (source_type == TypeManager.object_type && !target_is_value_type)
return new ClassCast (source, target_type);
+ //
+ // Unboxing conversion.
+ //
+ if (((source_type == TypeManager.enum_type &&
+ !(source is EmptyCast)) ||
+ source_type == TypeManager.value_type) && target_is_value_type)
+ return new UnboxCast (source, target_type);
//
// From any class S to any class-type T, provided S is a base class of T