haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Uncomparable abstract

Open ncannasse opened this issue 7 months ago • 2 comments

In the following example, we can compare abstracts physically while we would like to avoid that. I propose that we all some abstract to be tagged with metadata @:uncomparable so comparing them with == or != will trigger a similar error as we have with enums.

enum E {
  A;
  B( x : Int );
}

abstract Abs(E) {
   public inline function new(v:E) this = v;
}

class Test {
  static function main() {
    var a = A;
    var b = B(0);
    trace( a == b ); // error, which is fine
    
    var a = new Abs(a);
    var b = new Abs(b);
    trace(a == b); // false !
  }
}

ncannasse avatar Apr 07 '25 13:04 ncannasse