Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generators/cpp/gen/cppGen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,9 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args function_
output_i "int __Compare(const ::hx::Object* inRhs) const override {\n";
output_i (Printf.sprintf "\treturn dynamic_cast<const _hx_Closure_%i*>(inRhs) ? 0 : -1;\n" closure.close_id);
output_i "}\n";
output_i "std::type_index callableId() const override {\n";
output_i (Printf.sprintf "\treturn std::type_index{ typeid(_hx_Closure_%i) };\n" closure.close_id);
output_i "}\n";

let return =
match closure.close_type with TCppVoid -> "(void)" | _ -> "return"
Expand Down
5 changes: 4 additions & 1 deletion src/generators/genjvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,10 @@ class texpr_to_jvm
| [TObject(path1,_);sig2] when jc#has_typed_function path1 || path1 = haxe_function_path ->
code#swap;
fun_compare path1 sig2
| [(TObject _ | TArray _ | TMethod _) as t1;(TObject _ | TArray _ | TMethod _) as t2] ->
| [TMethod _;_] | [_;TMethod _] ->
jm#invokestatic haxe_jvm_path "compareFunctions" (method_sig [object_sig;object_sig] (Some TBool));
CmpNormal(op,TBool)
| [(TObject _ | TArray _) as t1;(TObject _ | TArray _) as t2] ->
CmpSpecial ((if op = CmpEq then code#if_acmp_ne else code#if_acmp_eq) t1 t2)
| [TDouble;TDouble] ->
let op = flip_cmp_op op in
Expand Down
4 changes: 4 additions & 0 deletions std/jvm/Jvm.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class Jvm {
return Reflect.compare(v1, v2);
}

static public function compareFunctions(v1:Dynamic, v2:Dynamic):Bool {
return Reflect.compareMethods(v1, v2);
}

static public function enumEq(v1:Dynamic, v2:Dynamic) {
if (!instanceof(v1, jvm.Enum)) {
return false;
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/src/unit/issues/Issue12746.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package unit.issues;

private class Event {}
private class MouseEvent extends Event {}
private class Foo {
public function onMouseMove(e:MouseEvent):Void {}

public function new() {}
}

class Issue12746 extends Test {
function test() {
#if !neko
final obj = new Foo();

final a:Event->Void = cast obj.onMouseMove;
final b:Event->Void = cast obj.onMouseMove;
t(a == b);

t(genericCast(obj.onMouseMove, obj.onMouseMove));
#else
utest.Assert.pass(); // See PR 12763 discussion
#end
}

static function genericCast<T:Event>(a:T->Void, b:T->Void):Bool {
var ca:Event->Void = cast a;
var cb:Event->Void = cast b;
return ca == cb;
}
}
Loading