nested types: generic types can't have nested types.
Bug: 201639797
Test: aidl_unittests
Change-Id: I5cf974681ffa34bfe8eda7312217d3b1ce97bc04
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 71c79fb..18c2710 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -1023,6 +1023,12 @@
success = success && t->CheckValid(typenames);
}
+ if (auto parameterizable = AsParameterizable();
+ parameterizable && parameterizable->IsGeneric() && !GetNestedTypes().empty()) {
+ AIDL_ERROR(this) << "Generic types can't have nested types.";
+ return false;
+ }
+
std::set<std::string> nested_type_names;
for (const auto& t : GetNestedTypes()) {
bool duplicated = !nested_type_names.emplace(t->GetName()).second;
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index e3a761b..10e8044 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1619,6 +1619,18 @@
HasSubstr("Unstructured parcelables should be at the root scope"));
}
+TEST_F(AidlTest, RejectGenericTypeWithNestedTypes) {
+ const string input_path = "p/Foo.aidl";
+ const string input =
+ "package p;\n"
+ "parcelable Foo<T> {\n"
+ " parcelable Bar {}\n"
+ "}";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse(input_path, input, typenames_, Options::Language::CPP));
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("Generic types can't have nested types."));
+}
+
TEST_F(AidlTest, HandleSyntaxErrorsInNestedDecl) {
const string input_path = "p/IFoo.aidl";
const string input =