HaxeFoundation / HaxeFoundation/haxe
[cpp] Bad null-check generation
- 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
Assessment
This issue has not been assessed yet.