HaxeFoundation / HaxeFoundation/haxe

[cpp] Abstract multitype as function parameter incorrect with dynamic @:to

Open
#6,476 3 comments 0 reactions 2 assignees Claimed by @Simn View on GitHub
platform-cpp
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

**Summary**: When an abstract multitype is used as a function parameter on cpp, the generated function definition is incorrect if there's a `@:to` for `T` or `Dynamic`, regardless of the order of `@:to`s.

Let's say `AMT` is an abstract multitype. If it realllly matters, `Concrete` is an interface, and you can repro this using `openfl.Vector`, which is "AMT" in my case.

```haxe
@:multiType(T)
abstract AMT(Concrete) {
public function new();
@:to static inline function toInt(t:Concrete) { return new IntAMT(); }
@:to static inline function toT(t:Concrete) { return new GenericAMT(); }
}
```

In the below example, within the function definition of `traceOut` in `Main.cpp`, `traceOut` is expecting a `GenericAMT`, causing the parameter to be null when I pass in the `IntAMT`. It should be expecting a `Concrete`.

```haxe
class Main {
static function main() {
var amt = new AMT();
trace(amt); // works fine
traceOut(amt); // null on cpp
}

static function traceOut(amt:AMT):Void {
trace(amt);
}
}
```

Flipping the order of `@:to`s doesn't affect the function definition.

When I remove the generic `@:to`, the function parameter becomes `Concrete`, as it should be.

Latest dev. Works in flash, doesn't on Windows or barebones cpp without OpenFL. I tried `(@:followWithAbstracts T)`, but that didn't do anything if it's supposed to.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.