Skip to content

[cpp] Invalid code on switch with enum from callable #12586

Description

@tobil4sk

Regression in #11151

https://github.com/HaxeCheckstyle/tokentree/blob/d6f75b95d037aafe1dbc97cf77352f37c0c74ff3/src/tokentree/TokenTree.hx#L119

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions