2003-04-19 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / mcs / ecore.cs
index ee129c5c702208b7089309425330b76fc7417e78..46a3c677a1a5e01ad9ecd576180fd6d508ca82b8 100755 (executable)
@@ -336,7 +336,7 @@ namespace Mono.CSharp {
 
                        if ((e is TypeExpr) || (e is ComposedCast)) {
                                if ((flags & ResolveFlags.Type) == 0) {
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
 
@@ -346,7 +346,7 @@ namespace Mono.CSharp {
                        switch (e.eclass) {
                        case ExprClass.Type:
                                if ((flags & ResolveFlags.VariableOrValue) == 0) {
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
                                break;
@@ -369,7 +369,7 @@ namespace Mono.CSharp {
                                        FieldInfo fi = ((FieldExpr) e).FieldInfo;
                                        
                                        Console.WriteLine ("{0} and {1}", fi.DeclaringType, fi.Name);
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
                                break;
@@ -729,7 +729,7 @@ namespace Mono.CSharp {
                        // notice that it is possible to write "ValueType v = 1", the ValueType here
                        // is an abstract class, and not really a value type, so we apply the same rules.
                        //
-                       if (target_type == TypeManager.object_type || target_type == TypeManager.value_type) {
+                       if (target_type == TypeManager.object_type) {
                                //
                                // A pointer type cannot be converted to object
                                // 
@@ -740,6 +740,11 @@ namespace Mono.CSharp {
                                        return new BoxedCast (expr);
                                if (expr_type.IsClass || expr_type.IsInterface || expr_type == TypeManager.enum_type)
                                        return new EmptyCast (expr, target_type);
+                       } else if (target_type == TypeManager.value_type) {
+                               if (expr_type.IsValueType)
+                                       return new BoxedCast (expr);
+                               if (expr is NullLiteral)
+                                       return new BoxedCast (expr);
                        } else if (expr_type.IsSubclassOf (target_type)) {
                                //
                                // Special case: enumeration to System.Enum.
@@ -2467,7 +2472,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Reports that we were expecting `expr' to be of class `expected'
                /// </summary>
-               public void Error118 (string expected)
+               public void Error_UnexpectedKind (string expected)
                {
                        string kind = "Unknown";
                        
@@ -2477,7 +2482,7 @@ namespace Mono.CSharp {
                               "' where a `" + expected + "' was expected");
                }
 
-               public void Error118 (ResolveFlags flags)
+               public void Error_UnexpectedKind (ResolveFlags flags)
                {
                        ArrayList valid = new ArrayList (10);