diff --git a/scripts/cxx-api/parser/member/function_member.py b/scripts/cxx-api/parser/member/function_member.py index 52929e42771..9d9ef6e66dd 100644 --- a/scripts/cxx-api/parser/member/function_member.py +++ b/scripts/cxx-api/parser/member/function_member.py @@ -65,6 +65,26 @@ class FunctionMember(Member): self.type = qualify_type_str(self.type, scope) self.arguments = qualify_arguments(self.arguments, scope) self._qualify_specialization_args(scope) + self._qualify_conversion_operator_type(scope) + + def _qualify_conversion_operator_type(self, scope: Scope) -> None: + """Qualify the type portion of conversion operator names. + + Conversion operators like ``operator jsi::Array`` contain a type + reference that may need namespace qualification (e.g., to + ``operator facebook::jsi::Array``). + """ + prefix = "operator " + if not self.name.startswith(prefix): + return + + type_part = self.name[len(prefix) :] + if not type_part or not (type_part[0].isalpha() or type_part[0] == "_"): + return + + qualified = qualify_type_str(type_part, scope) + if qualified != type_part: + self.name = prefix + qualified def to_string( self, diff --git a/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api index 691784f2ab9..b490eca3f47 100644 --- a/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api +++ b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api @@ -1,5 +1,5 @@ class test::Clss { - public operator Other() const; + public operator test::Other() const; } class test::Other { diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/snapshot.api b/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/snapshot.api new file mode 100644 index 00000000000..1b986391128 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/snapshot.api @@ -0,0 +1,7 @@ +struct outer::inner::Type { +} + + +struct outer::sibling::Clss { + public operator outer::inner::Type(); +} diff --git a/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/test.h b/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/test.h new file mode 100644 index 00000000000..1dec330e5d0 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/test.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace outer { + +namespace inner { +struct Type {}; +} // namespace inner + +namespace sibling { + +struct Clss { + operator inner::Type(); +}; + +} // namespace sibling + +} // namespace outer