Handle errors while parsing nested types

This fixes nullderef when there's a syntax error while parsing nested
types.

Fixes: 201578963
Test: aidl_unittests
Change-Id: I677d783f81f41a919e2da13dcbb7da2820378221
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index ab01940..c1a2137 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1606,6 +1606,18 @@
   EXPECT_THAT(GetCapturedStderr(), HasSubstr("Interfaces should be at the root scope"));
 }
 
+TEST_F(AidlTest, HandleSyntaxErrorsInNestedDecl) {
+  const string input_path = "p/IFoo.aidl";
+  const string input =
+      "package p;\n"
+      "interface IFoo {\n"
+      "  parcelable;\n"  // missing identifier
+      "}";
+  CaptureStderr();
+  EXPECT_EQ(nullptr, Parse(input_path, input, typenames_, Options::Language::CPP));
+  EXPECT_THAT(GetCapturedStderr(), HasSubstr("expecting identifier"));
+}
+
 TEST_F(AidlTest, RejectsNestedTypesWithDuplicateNames) {
   const string input_path = "p/Foo.aidl";
   const string input =