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
6 changes: 6 additions & 0 deletions src/generators/cpp/gen/cppGenClassImplementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let write_callable_header callable_name captures func return_type_str prefix out
| None ->
Printf.sprintf "\t%s() {} \n" callable_name |> output);

(* Override __Compare *)
output "\tint __Compare(const ::hx::Object* inRhs) const override {\n";
Printf.sprintf "\t\tauto casted = dynamic_cast<const %s*>(inRhs);\n" callable_name |> output;
output "\t\tif (!casted) { return -1; }\n";
Expand All @@ -28,6 +29,11 @@ let write_callable_header callable_name captures func return_type_str prefix out
output "\t\treturn 0;\n";
output "\t}\n";

(* Override callableId, Haxe function closures are only compared based on name, not signature *)
output "\tstd::type_index callableId() const override {\n";
Printf.sprintf "\t\treturn std::type_index{ typeid(%s) };\n" callable_name |> output;
output "\t}\n";

Printf.sprintf "\t%s HX_LOCAL_RUN(%s) override {\n" return_type_str (cpp_callable_args func.tcf_args prefix) |> output

let write_callable_trailer captures output =
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/src/unit/issues/Issue12872.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package unit.issues;

private class GenericHolder<T> {
public var value:T;
public function new() {}
}

private class ClassA {
public function new() {}
public function doSomething(x:Int) {}
}

private class ClassB {
public function new() {}
public function doSomethingElse(x:Int) {}
}

class Issue12872 extends Test {
function test() {
final a = new ClassA();
final b = new ClassB();

final fnA:Int->Void = a.doSomething;
final fnB:Int->Void = b.doSomethingElse;

f(fnA == fnB);
f(Reflect.compareMethods(fnA, fnB));

final castA:Dynamic->Void = cast fnA;
final castB:Dynamic->Void = cast fnB;

f(castA == castB);
f(Reflect.compareMethods(castA, castB));

var holder = new GenericHolder<Dynamic->Void>();
holder.value = castA;

f(holder.value == castB);
}
}
Loading