HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
297 stars 189 forks source link

Struct<NativeEnum, EnumHandler> does not work in switch expression #1131

Open kevinresol opened 3 months ago

kevinresol commented 3 months ago

I stumbled across this issue https://github.com/HaxeFoundation/hxcpp/issues/441 which points to this example code: https://github.com/HaxeFoundation/hxcpp/blob/8eeeee784cca9a271c023030d56e3f6db426076c/test/native/tests/TestNativeEnum.hx

Equality check ((...:SystemMetricStruct) == OS) in Haxe generates this c++ code, which works ✅ :

cpp::Struct<wxSystemMetric, cpp::EnumHandler> val = // ...
if (::hx::IsInstanceEq( wxSYS_OS, val )) { ... }

Switch case (switch (...:SystemMetricStruct) {case OS: ... }) in Haxe generates this c++ code, which does not work ❌ :

cpp::Struct<wxSystemMetric, cpp::EnumHandler> _hx_switch_0 = // ...
if (  (_hx_switch_0==wxSYS_OS) ) { ... }
Error: ./src/RunTests.cpp:235:34: error: use of overloaded operator '==' is ambiguous (with operand types 'cpp::Struct<wxSystemMetric, cpp::EnumHandler>' and 'wxSYS_OS')
                        if (  (_hx_switch_0==wxSYS_OS) ){