HaxeFoundation / HaxeFoundation/haxe

[HL] [Regression] Casting `Int` to `Null<Bool>` causes a compile time error on HL

Open
#13,007 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

### Haxe version
`5.0.0-preview.1+5f83789`
### Steps do reproduce

```haxe
class Main {
static function main() {
var x:Int = 1;
var nb:Null = cast x; // compiler failure on HL only
trace(nb);
}
}
```
Save it inside a `src` folder, then run `haxe -cp src -main Main --hl main.hl` on your terminal.

### Result
```bash
haxe -cp src -main Main --hl main.hl
[ERROR] (unknown position)

| Error: Compiler failure
| Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new
| Attach the following information:
| Haxe: 5.0.0-preview.1+5f83789; OS type: unix;
| File "src/generators/genhl.ml", line 1289, characters 16-23
| Called from Genhl.cast_to in file "src/generators/genhl.ml", line 1289, characters 9-23
| Called from Genhl.eval_to in file "src/generators/genhl.ml", line 1153, characters 10-25
| Called from Genhl.eval_expr in file "src/generators/genhl.ml", line 1759, characters 12-48
| Called from Genhl.eval_expr.loop in file "src/generators/genhl.ml", line 1798, characters 10-27
| Called from Genhl.eval_expr in file "src/generators/genhl.ml", line 1803, characters 10-17
| Called from Genhl.make_fun in file "src/generators/genhl.ml", line 3445, characters 8-33
| Called from Genhl.generate_static.loop in file "src/generators/genhl.ml", line 3522, characters 45-139
| Called from Stdlib__List.iter in file "list.ml", line 112, characters 12-15
| Called from Genhl.generate_type in file "src/generators/genhl.ml", line 3609, characters 2-56
| Called from Stdlib__List.iter in file "list.ml", line 112, characters 12-15
| Called from Genhl.generate in file "src/generators/genhl.ml", line 4356, characters 1-24
| Called from Std.finally in file "src/std.ml", line 24, characters 6-9
| Called from Compiler.compile in file "src/compiler/compiler.ml", line 391, characters 29-64
| Called from Compiler.compile_safe in file "src/compiler/compiler.ml", line 410, characters 1-5
| Called from Compiler.compile_safe in file "src/compiler/compiler.ml", line 456, characters 5-23
| Called from Compiler.compile_ctx.run in file "src/compiler/compiler.ml", lines 516-520, characters 2-3
| Called from Compiler.catch_completion_and_exit in file "src/compiler/compiler.ml", line 482, characters 2-9
| Called from HighLevel.entry.loop in file "src/compiler/highLevel.ml", line 88, characters 14-43
| Called from HighLevel.entry in file "src/compiler/highLevel.ml", line 95, characters 12-35
| Called from Dune__exe__Haxe in file "src/compiler/haxe.ml", line 165, characters 15-62
|
```

While the runtime behavior is inconsistent, only HashLink fails at compile time.
The same code compiles just fine on 4.3.7 for all targets, and on latest Nightly on all all targets except HL.

Contributor guide

Open the contributing guide

Research direction

Reproduce the sample with `haxe -cp src -main Main --hl main.hl`, then inspect `src/generators/genhl.ml` around line 1289 and the `Genhl.cast_to` call shown in the stack trace. Compare the HashLink path with other targets and the working Haxe versions. Done means the `Int` to `Null` sample compiles on HL without the compiler failure.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.