You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using Reflect.compareMethods with "callback" variables when variable signature is dynamic and method signature is something else causes the compareMethods to return false even though the methods are the same.
(This is breaking openFLs event system)
Run this example and you will see that callbackA and callbackC both points to testMethodX but when compared with compareMethods the result is false.
package;
classMain
{
staticvarcallbackA:Dynamic->String;
staticvarcallbackB:Dynamic->String;
staticvarcallbackC:Dynamic->String;
staticvarcallbackD:Dynamic->String;
staticfunctiontestMethodX(val:Int):String
{
return"X";
}
staticfunctiontestMethodY(val:Dynamic):String
{
return"Y";
}
staticfunctionmain()
{
callbackA=testMethodX;
callbackB=testMethodY;
callbackC=testMethodX;
callbackD=testMethodY;
trace("-- compare with the same variable --");
trace("callback A == calback A :"+Reflect.compareMethods(callbackA, callbackA) +" (Expected true)");
trace("callback B == calback B :"+Reflect.compareMethods(callbackB, callbackB) +" (Expected true)");
trace("");
trace("-- compare diffrent variables and different methods --");
trace("callback A == calback B :"+Reflect.compareMethods(callbackA, callbackB) +" (Expected false)");
trace("callback B == calback A :"+Reflect.compareMethods(callbackB, callbackA) +" (Expected false)");
trace("");
trace("-- compare same method diffrent variables --");
trace("callback A == calback C :"+Reflect.compareMethods(callbackA, callbackC) +" (Expected true) <-- this one returns the wrong value");
trace("callback B == calback D :"+Reflect.compareMethods(callbackB, callbackD) +" (Expected true)");
trace("");
trace("callback A and C is the same method however it returns false");
trace("The only diffrence from B and D is that the method signature is not dynamic, while the callback signature is");
trace("sanity check");
trace(callbackA(1) +" == "+callbackC(1));
trace(callbackB(1) +" == "+callbackD(1));
}
}
For some reason a normal Reflect.compare seems to work as expected, so this is aworkaround for now.
trace("-- compare with the same variable --");
trace("callback A == calback A :"+ (Reflect.compare(callbackA, callbackA) ==0) +" (Expected true)");
trace("callback B == calback B :"+ (Reflect.compare(callbackB, callbackB) ==0) +" (Expected true)");
trace("");
trace("-- compare diffrent variables and different methods --");
trace("callback A == calback B :"+ (Reflect.compare(callbackA, callbackB) ==0)+" (Expected false)");
trace("callback B == calback A :"+ (Reflect.compare(callbackB, callbackA) ==0) +" (Expected false)");
trace("");
trace("-- compare same method diffrent variables --");
trace("callback A == calback C :"+ (Reflect.compare(callbackA, callbackC) ==0) +" (Expected true)");
trace("callback B == calback D :"+ (Reflect.compare(callbackB, callbackD) ==0) +" (Expected true)");
The text was updated successfully, but these errors were encountered:
I think this is related to Haxe/HL code generator generating a custom wrapper for the assignments
callbackA = testMethodX and callbackC = testMethodY, which generates not equal functions. We should be able to tag somehow these methods as wrappers so we can go through them in Reflect.compareMethods, but the bytecode does not carry this information atm.
However, as a temporary workaround I think that doing the following should work:
using
Reflect.compareMethods
with "callback" variables when variable signature is dynamic and method signature is something else causes thecompareMethods
to return false even though the methods are the same.(This is breaking openFLs event system)
Run this example and you will see that callbackA and callbackC both points to testMethodX but when compared with compareMethods the result is false.
For some reason a normal
Reflect.compare
seems to work as expected, so this is aworkaround for now.The text was updated successfully, but these errors were encountered: