From 11072438f114241ce8ec7f870c4b3c4e8c3318dc Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 3 Mar 2026 01:00:16 -0800 Subject: [PATCH] Don't requalify already globally qualified identifiers (#55847) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55847 Changelog: [Internal] Disables name qualification on already globally qualified identifiers. Reviewed By: cortinico Differential Revision: D94901503 fbshipit-source-id: 22206b454c37e7e061abf34d64839f79c82eea1f --- scripts/cxx-api/parser/main.py | 4 ++- .../parser/utils/type_qualification.py | 4 +++ .../snapshot.api | 10 +++++++ .../test.h | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/test.h diff --git a/scripts/cxx-api/parser/main.py b/scripts/cxx-api/parser/main.py index f6e991fbb6b..7f7f0ff843f 100644 --- a/scripts/cxx-api/parser/main.py +++ b/scripts/cxx-api/parser/main.py @@ -87,7 +87,9 @@ def resolve_linked_text_name( refid = getattr(part.value, "refid", None) if refid and not in_string: ns = extract_namespace_from_refid(refid) - if ns and not text.startswith(ns): + # Skip re-qualification if text is already globally qualified + # (starts with "::") - it's already an absolute path + if ns and not text.startswith(ns) and not text.startswith("::"): # The text may already start with a trailing portion of # the namespace. For example ns="facebook::react::HighResDuration" # and text="HighResDuration::zero". We need to find the diff --git a/scripts/cxx-api/parser/utils/type_qualification.py b/scripts/cxx-api/parser/utils/type_qualification.py index 12feedc0579..db5ff592c96 100644 --- a/scripts/cxx-api/parser/utils/type_qualification.py +++ b/scripts/cxx-api/parser/utils/type_qualification.py @@ -31,6 +31,10 @@ def qualify_type_str(type_str: str, scope: Scope) -> str: if not type_str: return type_str + # Names starting with "::" are already globally qualified - skip re-qualification + if type_str.lstrip().startswith("::"): + return type_str + # Handle template arguments first: qualify types inside angle brackets angle_start = type_str.find("<") if angle_start != -1: diff --git a/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api new file mode 100644 index 00000000000..af18855b4a5 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api @@ -0,0 +1,10 @@ +struct other::Consumer { + public ::test::inner::MyType create(); + public void process(const ::test::inner::MyType & param); + public void processPtr(::test::inner::MyType * param); +} + + +struct test::inner::MyType { + public int value; +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/test.h b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/test.h new file mode 100644 index 00000000000..eacc3229618 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/test.h @@ -0,0 +1,28 @@ +/* + * 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 test { +namespace inner { + +struct MyType { + int value; +}; + +} // namespace inner +} // namespace test + +namespace other { + +struct Consumer { + void process(const ::test::inner::MyType ¶m); + void processPtr(::test::inner::MyType *param); + ::test::inner::MyType create(); +}; + +} // namespace other