+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
if (value >= 0)
return true;
}
-
- if (value == 0 && target_type.IsEnum)
- return true;
}
if (expr is LongConstant && target_type == TypeManager.uint64_type){
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
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) {