Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deepcake opened this issue Mar 25, 2024 · 0 comments
Open

Comments

@deepcake
Copy link

deepcake commented Mar 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant