HaxeFoundation / HaxeFoundation/haxe

`@:multiType`-inception instantiates non-existent constructors

Open
#10,318 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I have tried implementing a custom map abstract via `@:multiType` and have encountered a weird issue:

```haxe
class Test {
static function main() {
var x = new ObservableMap(['1' => 2]);
}
}

@:multiType(@:followWithAbstracts K)
abstract ObservableMap(ObservableMapImpl) {
public function new(?init:haxe.Constraints.IMap);

@:to static function toIntMap(dict:ObservableMapImpl, ?init:haxe.Constraints.IMap):ObservableMapImpl
return null;
}

class ObservableMapImpl {

}
```

The [generated js code](https://try.haxe.org/#2FE6402e) will contain `new haxe_ds_Map().set("1",2);` which depending on `js_es` will crash in one way or another - and other targets produce corresponding errors too.

Side note: I also tried `Map` for the initial values, with the same result. My guess is that there's so many levels of type parameters, that the compiler somehow doesn't realize it must select an implementation.

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.