HaxeFoundation / HaxeFoundation/haxe

Typing order error with generic and specific import order

Open
#11,152 10 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

We've been facing quite the head scratcher over at the Lime discord... Lime has a dependency chain involving a generic type that can be roughly simplified to this sample: https://try.haxe.org/#763D572a

Main.hx:
```haxe
import Generic;

class Main {
public function new() {
final generic = new Generic();
}

static function main() {}
}
```

Generic.hx:
```haxe
var main = new Main();

@:generic
class Generic {
public function new() {
trace(main);
}
}
```

This results in the error:
```
[ERROR] Generic.hx:5: lines 5-7

5 | public function new() {
6 | trace(main);
7 | }
|
| Field new has no expression (possible typing order issue)

[ERROR] Main.hx:5: characters 23-35

5 | final generic = new Generic();
| ^^^^^^^^^^^^
| While building Generic_Int
```

Removing the `@:generic` meta avoids the issue https://github.com/openfl/lime/pull/1662. In Lime's case, moving around types and simplifying certain dependency chains sometimes fixes the issue, but it's quite a fragile solution. In this example, removing the `import Generic;` at the top of Main.hx avoids the error somehow as well...

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.