Browse Source

[java/cs] Proper hashCode support for Haxe enums

Caue Waneck 12 năm trước cách đây
mục cha
commit
ea4e7ea513
3 tập tin đã thay đổi với 27 bổ sung0 xóa
  1. 1 0
      gencs.ml
  2. 13 0
      std/cs/internal/HxObject.hx
  3. 13 0
      std/java/internal/HxObject.hx

+ 1 - 0
gencs.ml

@@ -1409,6 +1409,7 @@ let configure gen =
               | TDynamic _, TEnum({ e_path = ([], "Bool") }, [])
               | TDynamic _, TAbstract({ a_path = ([], "Bool") }, []) -> true
               | _ -> false)
+          | "GetHashCode", TFun([],_) -> true
           | _ -> false
         in
 

+ 13 - 0
std/cs/internal/HxObject.hx

@@ -119,4 +119,17 @@ private class Enum
 		return true;
 	}
 
+	public function GetHashCode():Int
+	{
+		var h = 19;
+		if (params != null) for (p in params)
+		{
+			h = h * 31;
+			if (p != null)
+				h += untyped p.GetHashCode();
+		}
+		h += index;
+		return h;
+	}
+
 }

+ 13 - 0
std/java/internal/HxObject.hx

@@ -120,4 +120,17 @@ private class Enum
 		}
 		return true;
 	}
+
+	public function hashCode():Int
+	{
+		var h = 19;
+		if (params != null) for (p in params)
+		{
+			h = h * 31;
+			if (p != null)
+				h += untyped p.hashCode();
+		}
+		h += index;
+		return h;
+	}
 }