I was under the impression that .equals or Type.enumEq was for deep/valuetype equality and == is for shallow/sameinstance equality. But on the cpp target that does not seem to be the case? Is there a way around this, if we want to compare two enum values for instance identity on cpp target?
I think it should work
It does not.
class Test {
public static function main() {
final first = Foo.X(A);
final second = Foo.X(A);
trace(first == second);
}
}
enum Foo {
X(x:Bar);
Y;
}
enum Bar {
A;
B;
}
Prints:
Test.hx:5: true
With haxe 4.1.3 I am getting this compilation error:
src/Main.hx:5: characters 15-30 : You cannot directly compare enums with arguments. Use either `switch`, `match` or `Type.enumEq`
==
is for physical equality, nothing more. Example:
class Test {
static function main() {
compare(Y, Y);// true
compare(X(A), X(A));// false
var foo = X(A);
compare(foo, foo);// true
}
static function compare(a:Foo, b:Foo)
trace(a == b);
}
enum Foo {
X(x:Bar);
Y;
}
enum Bar {
A;
B;
}