From 0b1ce70b62ec15bc6a3590f100600afd83668f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 18 Mar 2026 09:29:02 -0700 Subject: [PATCH] Prevent identifiers being qualified to themselves (#56091) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56091 Changelog: [Internal] When qualifying a member, prevent taking itself as a target for qualification, to prevent types referencing themselves. Reviewed By: cipolleschi Differential Revision: D96455842 fbshipit-source-id: 2ed59a4688d0daa98db603a734283f41ffbe4ead --- scripts/cxx-api/parser/scope/scope.py | 9 ++++++++- .../snapshot.api | 7 +++++++ .../test.h | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/test.h diff --git a/scripts/cxx-api/parser/scope/scope.py b/scripts/cxx-api/parser/scope/scope.py index b7703683da4..e4de16635c4 100644 --- a/scripts/cxx-api/parser/scope/scope.py +++ b/scripts/cxx-api/parser/scope/scope.py @@ -26,6 +26,7 @@ class Scope(Generic[ScopeKindT]): self.location: str | None = None self._members: list[Member] = [] self._private_typedefs: dict[str, TypedefMember] = {} + self._qualifying_member: Member | None = None def get_qualified_name(self) -> str: """ @@ -85,6 +86,8 @@ class Scope(Generic[ScopeKindT]): # Check if it's a member (type alias, variable, etc.) for m in current_scope._members: + if m is current_scope._qualifying_member: + continue if m.name == base_first and not isinstance(m, FriendMember): prefix = current_scope.get_qualified_name() return f"{prefix}::{name}" if prefix else name @@ -110,7 +113,9 @@ class Scope(Generic[ScopeKindT]): matched_segments.append(path_segment) current_scope = current_scope.inner_scopes[base_name] elif any( - m.name == base_name and not isinstance(m, FriendMember) + m.name == base_name + and not isinstance(m, FriendMember) + and m is not current_scope._qualifying_member for m in current_scope._members ) or any( any(m.name == base_name for m in inner._members) @@ -194,7 +199,9 @@ class Scope(Generic[ScopeKindT]): typedef.close(self) for member in self.get_members(): + self._qualifying_member = member member.close(self) + self._qualifying_member = None self.kind.close(self) diff --git a/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/snapshot.api new file mode 100644 index 00000000000..20924222257 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/snapshot.api @@ -0,0 +1,7 @@ +struct test::Container { + public using Wrapper = test::Wrapper; +} + +template +struct test::Wrapper { +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/test.h b/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/test.h new file mode 100644 index 00000000000..1087db6ee5a --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_self_qualify_using_typedef/test.h @@ -0,0 +1,19 @@ +/* + * 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 +struct Wrapper {}; + +struct Container { + using Wrapper = Wrapper; +}; + +} // namespace test