Unexpected value conversion when using an abstract class with type param

Open
#668 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
c
Domain
compilers

Research direction

Run the linked try.haxe.org reproduction with Haxe 4.3.4 and compare the inline and non-inline versions of dispatch, checking both Bool and Int results against the reported values. Trace the HashLink runtime or generated-code handling for the abstract class's generic callback and value conversion; done means dispatch preserves the supplied values in both cases.

Written by the indexing model from the issue text.

Description

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

Dominant language
C
Stars
911
Forks
207
Avg merge
1d 21h
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HaxeFoundation/hashlink

All issues in HaxeFoundation/hashlink

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.