Skip to content

Unexpected value conversion when using an abstract class with type param #668

@deepcake

Description

@deepcake

Discovered a value conversion when using an abstract class with a type param (not sure what exactly causes this behavior). If you make the dispatch method inline, it will work as expected. <Int> is also converted - it prints 1074069696 no matter what value is passed.

https://try.haxe.org/#2c563180

class Test {
  static function main() {
    var s = new Signal1<Bool>();
    s.add(cb);
    s.dispatch(false); // <--- Test.hx:8: true
  }
  static function cb(v:Bool) {
    trace(v);
  }
}

@:forward(length, iterator)
abstract Signal1<T>(Array<T->Void>) {
  public inline function new() {
    this = new Array<T->Void>();
  }
  public inline function add(cb:T->Void) {
    this.push(cb);
  }
  public function dispatch(value:T) {
    for (cb in this) {
      cb(value);
    }
  }
}

Haxe 4.3.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions