Browse Source

[cs] Reverted 1cd97a3 ; Made really return the enum index as defined by the field's position, not its value. Closes #3232

Cauê Waneck 11 years ago
parent
commit
520bb0633d
3 changed files with 10 additions and 14 deletions
  1. 5 2
      std/cs/_std/Type.hx
  2. 4 3
      std/cs/internal/Runtime.hx
  3. 1 9
      typeload.ml

+ 5 - 2
std/cs/_std/Type.hx

@@ -374,9 +374,12 @@ import cs.internal.Runtime;
 
 	@:functionCode('
 		if (e is System.Enum)
-			return ((System.IConvertible) e).ToInt32(null);
-		else
+		{
+			System.Array values = System.Enum.GetValues(e.GetType());
+			return System.Array.IndexOf(values, e);
+		} else {
 			return ((haxe.lang.Enum) e).index;
+		}
 	')
 	public static function enumIndex( e : EnumValue ) : Int  untyped
 	{

+ 4 - 3
std/cs/internal/Runtime.hx

@@ -21,6 +21,7 @@
  */
 package cs.internal;
 import cs.Lib;
+import cs.Lib.*;
 import cs.NativeArray;
 import cs.NativeArray;
 import cs.system.Activator;
@@ -241,14 +242,14 @@ import cs.system.Object;
 
 			if (cv2 == null)
 			{
-				throw new cs.system.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString());
+				throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
 			}
 
 			switch(cv1.GetTypeCode())
 			{
 				case cs.system.TypeCode.String:
 					if (cv2.GetTypeCode() != cs.system.TypeCode.String)
-						throw new cs.system.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString());
+						throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
 					var s1 = Lib.as(v1,String);
 					var s2 = Lib.as(v2,String);
 					var i = 0,
@@ -271,7 +272,7 @@ import cs.system.Object;
 
 		if (c1 == null || c2 == null)
 		{
-			throw new cs.system.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString());
+			throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
 		}
 
 		return c1.CompareTo(c2);

+ 1 - 9
typeload.ml

@@ -2536,20 +2536,12 @@ let rec init_module_type ctx context_init do_init (decl,p) =
 					) l, rt)
 			) in
 			if PMap.mem c.ec_name e.e_constrs then error ("Duplicate constructor " ^ c.ec_name) p;
-			let eindex = try
-				match Meta.get Meta.CsNative c.ec_meta with
-					| (Meta.CsNative,[EConst (Int i), _], _) ->
-							int_of_string i
-					| _ -> raise Not_found
-				with Not_found ->
-					!index
-			in
 			let f = {
 				ef_name = c.ec_name;
 				ef_type = t;
 				ef_pos = p;
 				ef_doc = c.ec_doc;
-				ef_index = eindex;
+				ef_index = !index;
 				ef_params = params;
 				ef_meta = c.ec_meta;
 			} in