2
0
Эх сурвалжийг харах

[cs] Add equals / hashCode to Closure. Closes #3771

Cauê Waneck 10 жил өмнө
parent
commit
622b76774a

+ 14 - 0
std/cs/internal/Function.hx

@@ -77,4 +77,18 @@ package cs.internal;
 	{
 		return Runtime.callField(obj, field, hash, dynArgs);
 	}
+
+	public function Equals(obj:Dynamic):Bool
+	{
+		if (obj == null)
+			return false;
+
+		var c:Closure = cast obj;
+		return (c.obj == this.obj && c.field == this.field);
+	}
+
+	public function GetHashCode():Int
+	{
+		return obj.GetHashCode() ^ untyped field.GetHashCode();
+	}
 }

+ 15 - 1
std/java/internal/Function.hx

@@ -77,4 +77,18 @@ import java.internal.Runtime;
 	{
 		return Runtime.callField(obj, field, dynArgs);
 	}
-}
+
+	public function equals(obj:Dynamic):Bool
+	{
+		if (obj == null)
+			return false;
+
+		var c:Closure = cast obj;
+		return (c.obj == this.obj && c.field == this.field);
+	}
+
+	public function hashCode():Int
+	{
+		return obj.hashCode() ^ untyped field.hashCode();
+	}
+}

+ 12 - 0
tests/unit/src/unit/issues/Issue3771.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+class Issue3771 extends Test
+{
+	public function test()
+	{
+#if cs
+		var arr = [test];
+		eq(arr.indexOf(test),0);
+#end
+	}
+}