Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kevinresol opened this issue Jul 23, 2024 · 1 comment
Open

Comments

@kevinresol
Copy link

I stumbled across this issue #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) ){
@kevinresol
Copy link
Author

In fact, even the IsInstanceEq case doesn't really work because it is comparing a native enum directly with a cpp::Struct.

To make it work the compiler should also generate a c++ cast for the native enum value, i.e.

::hx::IsInstanceEq( (cpp::Struct<wxSystemMetric, cpp::EnumHandler>) wxSYS_OS, val )

The mentioned test file works only because of the extra function wrapping, where the arguments are explicitly typed as cpp::Struct, so any param going into the function will be cast correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant