From 4e1a8777ba6fd258390e0f7c8fc11bf42e5a14a8 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 11 Mar 2026 23:51:12 -0700 Subject: [PATCH] Requalify incorrect references produced by doxygen (#56058) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56058 Changelog: [Internal] Doxygen may incorrectly resolve reference to a friend declaration or inherited constructor instead of the actual friend or the base class. This diff updates the qualification algorithm to try to requalify cases like these. Reviewed By: cipolleschi Differential Revision: D96129278 fbshipit-source-id: fba4c78c74d43870a2a14f5eedce061ba6f2793d --- scripts/cxx-api/parser/scope.py | 20 ++++++++------- .../snapshot.api | 9 +++++++ .../test.h | 24 ++++++++++++++++++ .../snapshot.api | 7 ++++++ .../test.h | 25 +++++++++++++++++++ 5 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/test.h create mode 100644 scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h diff --git a/scripts/cxx-api/parser/scope.py b/scripts/cxx-api/parser/scope.py index 64afbca2c97..b4cc776cd05 100644 --- a/scripts/cxx-api/parser/scope.py +++ b/scripts/cxx-api/parser/scope.py @@ -409,16 +409,18 @@ class Scope(Generic[ScopeKindT]): if anchor_prefix: return f"{anchor_prefix}::{suffix}" return suffix - elif any( - isinstance(m, FriendMember) and m.name == base_name - for m in current_scope._members - ): - # The name matches a friend declaration, not a real member. - # Re-qualify from the remaining segments so the type resolves - # to its actual definition rather than the friend's owning class. - remaining = "::".join(path[i:]) - return self.qualify_name(remaining) else: + # Segment not found as an inner scope or a real member of + # the current scope. When inside a struct-like scope this + # typically means Doxygen's refid-based qualification + # incorrectly placed a type under a compound that does not + # actually contain it — for example a friend declaration or + # an inherited constructor reported as a member ref. Try + # to re-qualify from the remaining unmatched segments so the + # type resolves against the broader scope hierarchy. + if isinstance(current_scope.kind, StructLikeScopeKind): + remaining = "::".join(path[i:]) + return self.qualify_name(remaining) return None # Return qualified name with preserved template arguments diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api new file mode 100644 index 00000000000..41f269c2400 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api @@ -0,0 +1,9 @@ +class test::Derived : public test::Base { + public Derived(int value); + public using BaseAlias = test::Base; +} + +template +class test::Base { + public Base(int value); +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/test.h b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/test.h new file mode 100644 index 00000000000..cbfcf1c155a --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/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 test { + +template +class Base { + public: + Base(int value); +}; + +class Derived : public Base { + public: + using BaseAlias = Base; + using Base::Base; +}; + +} // namespace test diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api new file mode 100644 index 00000000000..dc34a4dfad7 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api @@ -0,0 +1,7 @@ +class test::ProviderRegistry { +} + +class test::Registry { + public Registry(const test::ProviderRegistry& provider); + public bool hasItem(int handle) const; +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h new file mode 100644 index 00000000000..54b18e30107 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h @@ -0,0 +1,25 @@ +/* + * 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 { + +class ProviderRegistry; + +class Registry { + public: + Registry(const ProviderRegistry &provider); + bool hasItem(int handle) const; + + private: + friend class ProviderRegistry; +}; + +class ProviderRegistry {}; + +} // namespace test