2010-06-17 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Thu, 17 Jun 2010 08:54:17 +0000 (08:54 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 17 Jun 2010 08:54:17 +0000 (08:54 -0000)
A fix for bug #614917
* convert.cs: Allow more undocumented 0 like values to enum type
conversions.

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

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

index 7aabc05dc3355ab1c40e2d924e654bb1f71a57b5..e346337cd85e00b67ec1cf25706f96fbae27fd7e 100644 (file)
@@ -1,3 +1,9 @@
+2010-06-17  Marek Safar  <marek.safar@gmail.com>
+
+       A fix for bug #614917
+       * convert.cs: Allow more undocumented 0 like values to enum type 
+       conversions.
+
 2010-06-17  Marek Safar  <marek.safar@gmail.com>
 
        * generic.cs, method.cs: Inflate copied type parameters from base
index 0e5006ebcb1bd8ae8e0ceca5c1cc07d1baf6356c..785e672424087076d191a837ad5f046ae426b8ee 100644 (file)
@@ -725,9 +725,6 @@ namespace Mono.CSharp {
                                        if (value >= 0)
                                                return true;
                                }
-
-                               if (value == 0 && target_type.IsEnum)
-                                       return true;
                        }
 
                        if (expr is LongConstant && target_type == TypeManager.uint64_type){
@@ -741,6 +738,18 @@ namespace Mono.CSharp {
                                        return true;
                        }
 
+                       if (expr is IntegralConstant && TypeManager.IsEnumType (target_type)) {
+                               var i = (IntegralConstant) expr;
+                               //
+                               // LAMESPEC: csc allows any constand like 0 values to be converted, including const float f = 0.0
+                               //
+                               // An implicit enumeration conversion permits the decimal-integer-literal 0
+                               // to be converted to any enum-type and to any nullable-type whose underlying
+                               // type is an enum-type
+                               //
+                               return i.IsZeroInteger;
+                       }
+
                        //
                        // If `expr_type' implements `target_type' (which is an iface)
                        // see TryImplicitIntConversion
@@ -1238,17 +1247,19 @@ namespace Mono.CSharp {
                        if (e != null)
                                return e;
 
-                       if (expr is IntConstant && TypeManager.IsEnumType (target_type)){
-                               Constant i = (Constant) expr;
+                       if (expr is IntegralConstant && TypeManager.IsEnumType (target_type)){
+                               var i = (IntegralConstant) expr;
                                //
-                               // LAMESPEC: Conversion from any 0 constant is allowed
+                               // LAMESPEC: csc allows any constand like 0 values to be converted, including const float f = 0.0
                                //
                                // An implicit enumeration conversion permits the decimal-integer-literal 0
                                // to be converted to any enum-type and to any nullable-type whose underlying
                                // type is an enum-type
                                //
-                               if (i.IsDefaultValue)
-                                       return new EnumConstant (i, target_type).Resolve (ec);
+                               if (i.IsZeroInteger) {
+                                       // Recreate 0 literal to remove any collected conversions
+                                       return new EnumConstant (new IntLiteral (0, i.Location), target_type).Resolve (ec);
+                               }
                        }
 
                        if (ec.IsUnsafe) {