All pastes #22159 Raw Edit

Someone

public text v1 · immutable
#22159 ·published 2005-09-05 17:04 UTC
rendered paste body

This is from:

		// TODO: move to constant
		/// <summary>
		///   Attempts to do a compile-time folding of a constant cast.
		/// </summary>
		Expression TryReduce (EmitContext ec, Type target_type)
		{
			if (expr.Type == target_type)
				return expr;

			if (TypeManager.IsEnumType (target_type) && TypeManager.EnumToUnderlying (target_type) == expr.Type)
				return new EnumConstant ((Constant)expr, target_type);


Index: expression.cs
===================================================================
--- expression.cs	(revision 49473)
+++ expression.cs	(working copy)
@@ -1337,7 +1337,7 @@
 			if (expr.Type == target_type)
 				return expr;
 
-			if (TypeManager.IsEnumType (target_type))
+			if (TypeManager.IsEnumType (target_type) && TypeManager.EnumToUnderlying (target_type) == expr.Type)
 				return new EnumConstant ((Constant)expr, target_type);
 
 			Expression real_expr = expr;