HaxeFoundation / HaxeFoundation/haxe

[cpp] Bad null-check generation

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

Description

```haxe
function main() {
var i:Int = 0;
trace(i == cast null);
}
```

On C++ this gives `false`. The dump looks like this:

```
[Binop:Bool]
[Local i(1):Int:Int]
==
[Cast:Int] [Const:Null>] null
```

What I expect to happen here is that the `null` gets cast to `Int` and thus becomes `0`, and then we have `0 == 0`. However, the C++ generator emits this:

```cpp
void Main_Fields__obj::main(){
HX_STACKFRAME(&_hx_pos_14ea8b63d5b8313b_1_main)
HXLINE( 2) int i = 0;
HXLINE( 3) ::haxe::Log_obj::trace(::hx::IsNull( i ),::hx::SourceInfo(HX_("source/Main.hx",91,d3,a7,40),3,HX_("_Main.Main_Fields_",76,cc,48,1a),HX_("main",39,38,56,48)));
}
```

So it looks like it simply ignores the `Cast` node.

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.