From 7b3277f358c951f0421a115fead1c00b5c71bc80 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 26 Mar 2026 08:40:54 -0700 Subject: [PATCH] Qualify conversion operator type names in the snapshot (#56220) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56220 Changelog: [Internal] Conversion operators like `operator jsi::Array` contain a type reference in their name that was not being fully qualified. This diff adds a `_qualify_conversion_operator_type` step to `FunctionMember.close()` that detects conversion operators and qualifies the type portion of the name using the same mechanism already used for return types and arguments. Reviewed By: cipolleschi Differential Revision: D98124781 fbshipit-source-id: 7baf2b6f31fcbf2fdab43457b5792558d774b043 --- .../cxx-api/parser/member/function_member.py | 20 ++++++++++++++++ .../snapshot.api | 2 +- .../snapshot.api | 7 ++++++ .../test.h | 24 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_qualify_conversion_operator_type/test.h 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