From e753001996fd82d6805221ffcf8cd55202b02bf7 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Mon, 13 Jan 2025 22:42:05 +0100 Subject: [PATCH] fix: fix test_element_type test In some rare cases the find_value_type function would find multiple declarations. The logic in the function prevented to return the right value type, so I inverted it which fixes one more test on macOS Fixes: FAILED tests/test_vector_traits.py::test_element_type - RuntimeError: Unable to find out vector '::std::vector' key\value type. --- .../declarations/traits_impl_details.py | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/pygccxml/declarations/traits_impl_details.py b/src/pygccxml/declarations/traits_impl_details.py index b9fce594..3d452fc8 100644 --- a/src/pygccxml/declarations/traits_impl_details.py +++ b/src/pygccxml/declarations/traits_impl_details.py @@ -50,39 +50,40 @@ def find_value_type(global_ns, value_type_str): name=value_type_str, function=lambda decl: not isinstance(decl, calldef.calldef_t), allow_empty=True) - if not found: - no_global_ns_value_type_str = value_type_str[2:] - if no_global_ns_value_type_str in cpptypes.FUNDAMENTAL_TYPES: - return cpptypes.FUNDAMENTAL_TYPES[no_global_ns_value_type_str] - elif type_traits.is_std_string(value_type_str): - string_ = global_ns.typedef('::std::string') - return type_traits.remove_declarated(string_) - elif type_traits.is_std_wstring(value_type_str): - string_ = global_ns.typedef('::std::wstring') - return type_traits.remove_declarated(string_) + + if len(found) == 1: + return found[0] + + no_global_ns_value_type_str = value_type_str[2:] + if no_global_ns_value_type_str in cpptypes.FUNDAMENTAL_TYPES: + return cpptypes.FUNDAMENTAL_TYPES[no_global_ns_value_type_str] + elif type_traits.is_std_string(value_type_str): + string_ = global_ns.typedef('::std::string') + return type_traits.remove_declarated(string_) + elif type_traits.is_std_wstring(value_type_str): + string_ = global_ns.typedef('::std::wstring') + return type_traits.remove_declarated(string_) + else: + value_type_str = no_global_ns_value_type_str + has_const = value_type_str.startswith('const ') + if has_const: + value_type_str = value_type_str[len('const '):] + has_pointer = value_type_str.endswith('*') + if has_pointer: + value_type_str = value_type_str[:-1] + found = None + if has_const or has_pointer: + found = impl_details.find_value_type( + global_ns, + value_type_str) + if not found: + return None else: - value_type_str = no_global_ns_value_type_str - has_const = value_type_str.startswith('const ') + if isinstance(found, class_declaration.class_types): + return cpptypes.declarated_t(found) if has_const: - value_type_str = value_type_str[len('const '):] - has_pointer = value_type_str.endswith('*') + return cpptypes.const_t(found) if has_pointer: - value_type_str = value_type_str[:-1] - found = None - if has_const or has_pointer: - found = impl_details.find_value_type( - global_ns, - value_type_str) - if not found: - return None - else: - if isinstance(found, class_declaration.class_types): - return cpptypes.declarated_t(found) - if has_const: - return cpptypes.const_t(found) - if has_pointer: - return cpptypes.pointer_t(found) - if len(found) == 1: - return found[0] + return cpptypes.pointer_t(found) return None