Skip to content

Commit 94f40e7

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Strip leading :: for globally qualified identifiers (facebook#56033)
Summary: Pull Request resolved: facebook#56033 Changelog: [Internal] Currently, if the source code uses globally qualified identifiers, those will be kept in the snapshot without changes. Since in the output, everything is fully qualified, the leading `::` can be stripped from those. Reviewed By: cortinico Differential Revision: D95947334 fbshipit-source-id: 9592b00bd896679dda90ed56d32024b22752d2b7
1 parent 7f6790b commit 94f40e7

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

scripts/cxx-api/parser/utils/type_qualification.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def _qualify_type_str_impl(type_str: str, scope: Scope, qualify_base: bool) -> s
7070
return type_str
7171

7272
# Names starting with "::" are already globally qualified - skip re-qualification
73-
if type_str.lstrip().startswith("::"):
74-
return type_str
73+
if type_str.lstrip().startswith("::") and qualify_base:
74+
return type_str[2:]
7575

7676
# Handle template arguments first: qualify types inside angle brackets
7777
angle_start = type_str.find("<")
@@ -105,7 +105,9 @@ def _qualify_type_str_impl(type_str: str, scope: Scope, qualify_base: bool) -> s
105105

106106
# Recursively qualify the suffix (handles nested templates, pointers, etc.)
107107
qualified_suffix = (
108-
_qualify_type_str_impl(suffix, scope, qualify_base) if suffix else ""
108+
_qualify_type_str_impl(suffix, scope, qualify_base=False)
109+
if suffix
110+
else ""
109111
)
110112

111113
return qualified_prefix + qualified_template + qualified_suffix

scripts/cxx-api/tests/snapshots/should_not_requalify_globally_qualified_type/snapshot.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct other::Consumer {
2-
public ::test::inner::MyType create();
3-
public void process(const ::test::inner::MyType& param);
4-
public void processPtr(::test::inner::MyType* param);
2+
public test::inner::MyType create();
3+
public void process(const test::inner::MyType& param);
4+
public void processPtr(test::inner::MyType* param);
55
}
66

77

0 commit comments

Comments
 (0)