HaxeFoundation / HaxeFoundation/haxe

[cpp] unnecessary Dynamics with optional arguments with default values

Open
#7,143 3 comments 0 reactions 1 assignee Claimed by @hughsando View on GitHub
platform-cpp
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

This Haxe code:

```haxe
class Main {
public static function main() {
foobar();
foobar2();
}

static function foobar(def:Int = 0) {}
static function foobar2(?def:Int = 0) {}
}
```

Generates the following C++ code:

```cpp
void Main_obj::main(){
HX_STACKFRAME(&_hx_pos_e47a9afac0942eb9_2_main)
HXLINE( 3) ::Main_obj::foobar(null());
HXLINE( 4) ::Main_obj::foobar2(null());
}

STATIC_HX_DEFINE_DYNAMIC_FUNC0(Main_obj,main,(void))

void Main_obj::foobar(hx::Null< int > __o_def){
int def = __o_def.Default(0);
HX_STACKFRAME(&_hx_pos_e47a9afac0942eb9_7_foobar)
}

STATIC_HX_DEFINE_DYNAMIC_FUNC1(Main_obj,foobar,(void))

void Main_obj::foobar2( ::Dynamic __o_def){
::Dynamic def = __o_def.Default(0);
HX_STACKFRAME(&_hx_pos_e47a9afac0942eb9_8_foobar2)
}

STATIC_HX_DEFINE_DYNAMIC_FUNC1(Main_obj,foobar2,(void))
```

Note how `foobar`'s argument is properly typed as `hx::Null`, whereas in `foobar2` it is `Dynamic` (and presumably slower as a result). According to @nadako, it should be possible to generate `foobar2`'s argument as `hx::Null` too in this case.

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.