Skip to content

Commit d531d8c

Browse files
vitautfacebook-github-bot
authored andcommitted
Report an error for cpp2.deprecated_enum_unscoped
Summary: Report an error for `cpp2.deprecated_enum_unscoped` support for which we recently removed. Reviewed By: iahs Differential Revision: D71487259 fbshipit-source-id: 783dbcbb3e8ada99c95103f92db1e1dfb39cae02
1 parent 669a3b3 commit d531d8c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

thrift/compiler/sema/standard_validator.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,8 @@ void deprecate_annotations(sema_context& ctx, const t_named& node) {
14291429
{"erl.default_value", erlang("DefaultValue")},
14301430
{"iq.node_type", erlang("Iq")},
14311431
};
1432-
std::set<std::string> removed_annotations = {"cpp2.declare_bitwise_ops"};
1432+
std::set<std::string> removed_annotations = {
1433+
"cpp2.declare_bitwise_ops", "cpp2.deprecated_enum_unscoped"};
14331434
std::map<std::string, std::string> removed_prefixes = {{"rust.", "rust"}};
14341435

14351436
for (const auto& [k, v] : node.annotations()) {
@@ -1448,6 +1449,10 @@ void deprecate_annotations(sema_context& ctx, const t_named& node) {
14481449
}
14491450
bool directly_deprecated = deprecations.count(k) != 0;
14501451
if (!prefix && !directly_deprecated) {
1452+
if (removed_annotations.count(k) != 0) {
1453+
ctx.error("invalid annotation {}", k);
1454+
continue;
1455+
}
14511456
continue;
14521457
}
14531458
std::string replacement;

thrift/compiler/test/compiler_test.cc

+11-8
Original file line numberDiff line numberDiff line change
@@ -786,19 +786,22 @@ TEST(CompilerTest, removed_annotations) {
786786
check_compile(R"(
787787
include "thrift/annotation/thrift.thrift"
788788
789-
enum E {} (cpp2.declare_bitwise_ops)
789+
enum E1 {} (cpp2.declare_bitwise_ops)
790790
# expected-error@-1: The annotation cpp2.declare_bitwise_ops has been removed. Please use @thrift.BitmaskEnum instead.
791791
792792
@thrift.DeprecatedUnvalidatedAnnotations{items = {"cpp2.declare_bitwise_ops": "1"}}
793-
enum F {}
793+
enum E2 {}
794794
# expected-error@-2: The annotation cpp2.declare_bitwise_ops has been removed. Please use @thrift.BitmaskEnum instead.
795795
796+
enum E3 {} (cpp2.deprecated_enum_unscoped)
797+
# expected-error@-1: invalid annotation cpp2.deprecated_enum_unscoped
798+
796799
struct A {
797-
1: i64 removed_unstructured (rust.foo)
798-
# expected-error@-1: The annotation rust.foo has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
799-
@thrift.DeprecatedUnvalidatedAnnotations{items = {"rust.foo": "1"}}
800-
2: i64 removed_catchall
801-
# expected-error@-2: The annotation rust.foo has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
800+
1: i64 removed_unstructured (rust.foo)
801+
# expected-error@-1: The annotation rust.foo has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
802+
@thrift.DeprecatedUnvalidatedAnnotations{items = {"rust.foo": "1"}}
803+
2: i64 removed_catchall
804+
# expected-error@-2: The annotation rust.foo has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
802805
}
803806
804807
typedef map<string, string> (rust.type = "HashMap") HashMap
@@ -808,7 +811,7 @@ TEST(CompilerTest, removed_annotations) {
808811
typedef S T
809812
810813
service J {
811-
i64 foo(1: i64 arg (rust.name = "bar")) # expected-error: The annotation rust.name has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
814+
i64 foo(1: i64 arg (rust.name = "bar")) # expected-error: The annotation rust.name has been removed. Please use a structured annotation from thrift/annotation/rust.thrift instead.
812815
}
813816
)");
814817
}

0 commit comments

Comments
 (0)