HaxeFoundation / HaxeFoundation/haxe

Abstract typing discrepancy

Open
#7,598 2 comments 0 reactions 0 assignees View on GitHub
feature-abstracts
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

When typing the following code:

```haxe
abstract ArrayWrap(std.Array) from std.Array to std.Array
{
inline public function new()
{
this = [];
}
}

class Main
{
static function main()
{
var array:ArrayWrap = [];
trace(array[0].length);
}
}
````

We get:
```
[Field:Unknown<2>]
[Array:{ length : Unknown<2> }]
[Local array(3772):ArrayWrap:ArrayWrap]
[Const:Int] 0
[FAnon:Unknown<2>] length
```

Replacing `ArrayWrap` by `Array` instead produces (more correct):

```
[Field:Dynamic]
[Array:Dynamic]
[Local array(3772):Array:Array]
[Const:Int] 0
[FDynamic:Dynamic] length
```

This causes HL to compile invalid bytecode in the first case.
Related issue: https://github.com/HaxeFoundation/hashlink/issues/201

@Simn if we want to keep a difference in typing, we should at least have a TCast somewhere, I think.

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.