Skip to content

Commit d4587fb

Browse files
thedavekwonfacebook-github-bot
authored andcommitted
Update @cpp.DeprecatedTerseWrite codemod to ignore fields in Union
Summary: union fields are not eligibile for deprecated_terse_write Reviewed By: pranavtbhat Differential Revision: D68795539 fbshipit-source-id: adbf94d1563454b2e987e1580572102bc7e9e717
1 parent 0597d2f commit d4587fb

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

thrift/compiler/codemod/annotate_deprecated_terse_writes_fields.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ class AnnonateDeprecatedTerseWriteFields final {
6161
bool any_annotated = false;
6262

6363
const_ast_visitor visitor;
64-
visitor.add_field_visitor([&](const t_field& field) {
65-
any_annotated |= maybe_annotate_field(field);
64+
visitor.add_structured_definition_visitor([&](const t_structured& strct) {
65+
if (strct.is_union()) {
66+
return;
67+
}
68+
for (const t_field& field : strct.fields()) {
69+
any_annotated |= maybe_annotate_field(field);
70+
}
6671
});
6772
visitor(program_);
6873

thrift/compiler/codemod/annotate_deprecated_terse_writes_fields_test.py

+26
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ def test_basic_replace(self):
5656
7: MyStruct g (cpp.ref_type = "shared");
5757
}
5858
59+
union NoOpFieldsUnion {
60+
1: i32 a;
61+
}
62+
5963
struct ShouldAnnotateFields {
6064
1: string a;
6165
2: string b (cpp.ref = "true");
6266
3: MyStruct c (cpp.ref = "true");
6367
4: string d (cpp.ref_type = "shared");
6468
}
69+
70+
exception ShouldAnnotateFieldsException {
71+
1: string a;
72+
2: string b (cpp.ref = "true");
73+
3: MyStruct c (cpp.ref = "true");
74+
4: string d (cpp.ref_type = "shared");
75+
}
6576
"""
6677
),
6778
)
@@ -92,6 +103,10 @@ def test_basic_replace(self):
92103
7: MyStruct g (cpp.ref_type = "shared");
93104
}
94105
106+
union NoOpFieldsUnion {
107+
1: i32 a;
108+
}
109+
95110
struct ShouldAnnotateFields {
96111
@cpp.DeprecatedTerseWrite
97112
1: string a;
@@ -102,6 +117,17 @@ def test_basic_replace(self):
102117
@cpp.DeprecatedTerseWrite
103118
4: string d (cpp.ref_type = "shared");
104119
}
120+
121+
exception ShouldAnnotateFieldsException {
122+
@cpp.DeprecatedTerseWrite
123+
1: string a;
124+
@cpp.DeprecatedTerseWrite
125+
2: string b (cpp.ref = "true");
126+
@cpp.DeprecatedTerseWrite
127+
3: MyStruct c (cpp.ref = "true");
128+
@cpp.DeprecatedTerseWrite
129+
4: string d (cpp.ref_type = "shared");
130+
}
105131
"""
106132
),
107133
)

0 commit comments

Comments
 (0)