Skip to content

Commit 7b3277f

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Qualify conversion operator type names in the snapshot (facebook#56220)
Summary: Pull Request resolved: facebook#56220 Changelog: [Internal] Conversion operators like `operator jsi::Array` contain a type reference in their name that was not being fully qualified. This diff adds a `_qualify_conversion_operator_type` step to `FunctionMember.close()` that detects conversion operators and qualifies the type portion of the name using the same mechanism already used for return types and arguments. Reviewed By: cipolleschi Differential Revision: D98124781 fbshipit-source-id: 7baf2b6f31fcbf2fdab43457b5792558d774b043
1 parent f516811 commit 7b3277f

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

scripts/cxx-api/parser/member/function_member.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ def close(self, scope: Scope):
6565
self.type = qualify_type_str(self.type, scope)
6666
self.arguments = qualify_arguments(self.arguments, scope)
6767
self._qualify_specialization_args(scope)
68+
self._qualify_conversion_operator_type(scope)
69+
70+
def _qualify_conversion_operator_type(self, scope: Scope) -> None:
71+
"""Qualify the type portion of conversion operator names.
72+
73+
Conversion operators like ``operator jsi::Array`` contain a type
74+
reference that may need namespace qualification (e.g., to
75+
``operator facebook::jsi::Array``).
76+
"""
77+
prefix = "operator "
78+
if not self.name.startswith(prefix):
79+
return
80+
81+
type_part = self.name[len(prefix) :]
82+
if not type_part or not (type_part[0].isalpha() or type_part[0] == "_"):
83+
return
84+
85+
qualified = qualify_type_str(type_part, scope)
86+
if qualified != type_part:
87+
self.name = prefix + qualified
6888

6989
def to_string(
7090
self,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class test::Clss {
2-
public operator Other() const;
2+
public operator test::Other() const;
33
}
44

55
class test::Other {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct outer::inner::Type {
2+
}
3+
4+
5+
struct outer::sibling::Clss {
6+
public operator outer::inner::Type();
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace outer {
11+
12+
namespace inner {
13+
struct Type {};
14+
} // namespace inner
15+
16+
namespace sibling {
17+
18+
struct Clss {
19+
operator inner::Type();
20+
};
21+
22+
} // namespace sibling
23+
24+
} // namespace outer

0 commit comments

Comments
 (0)