Repository navigation
[cpp] Invalid code on switch with enum from callable #12586
Copy link
Copy link
Closed
Description
Regression in #11151
Error: ./src/tokentree/TokenTree.cpp: In member function ‘void tokentree::TokenTree_obj::internalFilterCallback(hx::Callable<hx::ObjectPtr<tokentree::FilterResult_obj>(hx::ObjectPtr<tokentree::TokenTree_obj>, int)>, Array<Dynamic>, Dynamic)’:
./src/tokentree/TokenTree.cpp:551:90: error: ‘class hx::ObjectPtr<tokentree::FilterResult_obj>’ has no member named ‘StaticCast’
551 | HXLINE( 119) switch((int)(callback(::hx::ObjectPtr<OBJ_>(this),depth).StaticCast< ::hx::EnumBase >()->_hx_getIndex())){
| ^~~~~~~~~~
./src/tokentree/TokenTree.cpp:551:117: error: expected primary-expression before ‘>’ token
551 | HXLINE( 119) switch((int)(callback(::hx::ObjectPtr<OBJ_>(this),depth).StaticCast< ::hx::EnumBase >()->_hx_getIndex())){
| ^
./src/tokentree/TokenTree.cpp:551:119: error: expected primary-expression before ‘)’ token
551 | HXLINE( 119) switch((int)(callback(::hx::ObjectPtr<OBJ_>(this),depth).StaticCast< ::hx::EnumBase >()->_hx_getIndex())){
| ^
At global scope:
cc1plus: note: unrecognized command-line option ‘-Wno-inconsistent-missing-override’ may have been intended to silence earlier diagnostics
Stripped down sample:
enum E {
A;
B;
}
function main() {
final callback:() -> E = () -> cast null;
trace(callback().match(A));
}Error: ./src/_Main/Main_Fields_.cpp: In static member function ‘static void _Main::Main_Fields__obj::main()’:
./src/_Main/Main_Fields_.cpp:69:41: error: ‘class hx::ObjectPtr<E_obj>’ has no member named ‘StaticCast’
69 | HXDLIN( 8) if ((callback().StaticCast< ::hx::EnumBase >()->_hx_getIndex() == 0)) {
| ^~~~~~~~~~
./src/_Main/Main_Fields_.cpp:69:68: error: expected primary-expression before ‘>’ token
69 | HXDLIN( 8) if ((callback().StaticCast< ::hx::EnumBase >()->_hx_getIndex() == 0)) {
| ^
./src/_Main/Main_Fields_.cpp:69:70: error: expected primary-expression before ‘)’ token
69 | HXDLIN( 8) if ((callback().StaticCast< ::hx::EnumBase >()->_hx_getIndex() == 0)) {
| ^
Seems like it should be generating callback()->_hx_getIndex() instead of callback().StaticCast< ::hx::EnumBase >()->_hx_getIndex(), since it's not dynamic anymore.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
tobil4sk commentedon Feb 10, 2026
@Aidan63 thanks for looking into it! With your patch my original program is compiling fine, and so is formatter.
However, I don't think the test case is actually covering it since the callable result is a regular function argument, not a switch/match. Without your patch it generated this, which still compiled fine for me:
I think we need a test case like this, with an explicit match or switch expression:
I was going to open a PR to add it, but when I added that test the error came back. I was confused because it's the same as my original sample. It turns out, the unit tests are using
-D analyzer-optimize, and if I add that it also brings it back:tobil4sk commentedon Feb 13, 2026
@Simn would you mind reopening this? I don't have permission to.
TLDR is that the error is still present when compiling the sample with
-D analyzer-optimizeAidan63 commentedon Mar 3, 2026
I've got a proper fix for this now (https://github.com/Aidan63/haxe/tree/cpp-enum-callable) and have updated that test. I'm just working on fixing one failing cppia test (Issue6560)
Aidan63 commentedon Mar 9, 2026
Should be properly fixed now.
tobil4sk commentedon Mar 26, 2026
Seems like it works now with
-D analyzer-optimize, but it is broken again with the analyzer disabled... 😅The formatter benchmarks are still failing to build.
Could we reopen?
tobil4sk commentedon May 6, 2026
@Aidan63 thanks! Formatter cpp benchmarks are back now