2007-11-07 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Wed, 7 Nov 2007 19:09:08 +0000 (19:09 -0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 7 Nov 2007 19:09:08 +0000 (19:09 -0000)
  A fix for bug #324242
  * covert.cs: Added a conversion from any nullable-type with an
  underlying enum-type to the type System.Enum.

svn path=/trunk/mcs/; revision=89148

mcs/mcs/ChangeLog
mcs/mcs/convert.cs

index 17783b30bb210ebc41194b89759325b9cfbba869..6587557858714c0d30e15d12481b9a009fa7ef47 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-07  Marek Safar  <marek.safar@gmail.com>
+
+       A fix for bug #324242
+       * covert.cs: Added a conversion from any nullable-type with an 
+       underlying enum-type to the type System.Enum.
+       
 2007-11-07  Marek Safar  <marek.safar@gmail.com>
 
        A fix for bug #324222
index a649b054d7cbdaaf2080d4045f558948fdda63d4..7be745f81db9eb1c01ae58ff0f393ade8bea21f2 100644 (file)
@@ -404,12 +404,10 @@ namespace Mono.CSharp {
                                                                   out bool use_class_cast)
                {
                        Type expr_type = expr.Type;
-
                        use_class_cast = false;
-
+                       
                        //
-                       // 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.
+                       // From any value-type to the type object.
                        //
                        if (target_type == TypeManager.object_type) {
                                //
@@ -419,15 +417,29 @@ namespace Mono.CSharp {
                                        return false;
 
                                return TypeManager.IsValueType (expr_type);
-                       } else if (target_type == TypeManager.value_type) {
+                       }
+                       
+                       //
+                       // From any value-type to the type System.ValueType.
+                       //
+                       if (target_type == TypeManager.value_type)
                                return TypeManager.IsValueType (expr_type);
-                       } else if (TypeManager.IsSubclassOf (expr_type, target_type)) {
+
+                       if (target_type == TypeManager.enum_type) {
                                //
-                               // Special case: enumeration to System.Enum.
-                               // System.Enum is not a value type, it is a class, so we need
-                               // a boxing conversion
+                               // From any enum-type to the type System.Enum.
                                //
-                               if (expr_type.IsEnum || TypeManager.IsGenericParameter (expr_type))
+                               if (expr_type.IsEnum)
+                                       return true;
+                               //
+                               // From any nullable-type with an underlying enum-type to the type System.Enum
+                               //
+                               if (TypeManager.IsNullableType (expr_type))
+                                       return TypeManager.GetTypeArguments (expr_type) [0].IsEnum;
+                       }
+                       
+                       if (TypeManager.IsSubclassOf (expr_type, target_type)) {
+                               if (TypeManager.IsGenericParameter (expr_type))
                                        return true;
 
                                return false;