HaxeFoundation / HaxeFoundation/haxe

Odd type error comparing certain values (X should be Y)

Open
#12,590 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

https://try.haxe.org/#06dE6c4C

```haxe
function main() {
{a:1} == {a:1.0};
[1] == [1.0];
Type.getClass([1]) == Type.getClass([1.0]);
}
```
All three of these statements fail unexpectedly at compile time, with an odd error:
```
[ERROR] Test.hx:3: characters 17-20

3 | {a:1} == {a:1.0};
| ^^^
| Float should be Int

[ERROR] Test.hx:4: characters 13-16

4 | [1] == [1.0];
| ^^^
| Float should be Int

[ERROR] Test.hx:5: characters 5-47

5 | Type.getClass([1]) == Type.getClass([1.0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| error: Float should be Int
| have: Null>
| want: Null>
```
They stop erroring if you swap the places of `1` and `1.0`.

Seems a bit unintuitive considering all of these statements would be fine at runtime, yet the compiler disallows it.

Contributor guide

Open the contributing guide

Research direction

Start by running the linked try.haxe.org reproduction and compare the three equality expressions, including the behavior when the operands are swapped. Trace the compiler's type-checking path for object literals, arrays, and Type.getClass calls. Done means these valid runtime comparisons no longer produce the reported Float should be Int error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.