mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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
This commit is contained in:
1 parent
91c6c4d4ae
commit
0b1ce70b62
3 files changed
+34
-1
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
struct test::Container {
|
||||
public using Wrapper = test::Wrapper<int>;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct test::Wrapper {
|
||||
}
|
||||
@@ -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 <typename T>
|
||||
struct Wrapper {};
|
||||
|
||||
struct Container {
|
||||
using Wrapper = Wrapper<int>;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
Reference in new issue
Block a user