aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aidl_language_y.yy7
-rw-r--r--aidl_unittest.cpp7
2 files changed, 10 insertions, 4 deletions
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index 95185798..3078dae3 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -772,10 +772,9 @@ parameter_non_empty_list
annotation
: ANNOTATION {
- auto annot = AidlAnnotation::Parse(loc(@1), $1->GetText(), {}, $1->GetComments());
- if (annot) {
- $$ = annot.release();
- } else {
+ // release() returns nullptr if unique_ptr is empty.
+ $$ = AidlAnnotation::Parse(loc(@1), $1->GetText(), {}, $1->GetComments()).release();
+ if (!$$) {
ps->AddError();
}
delete $1;
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 782e1504..6c8f4764 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -647,6 +647,13 @@ TEST_P(AidlTest, ParseDescriptorAnnotation) {
ASSERT_EQ("IBar", interface->GetDescriptor());
}
+TEST_P(AidlTest, UnknownAnnotation) {
+ const string oneway_method = "package a; @Unknown interface IFoo { }";
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("not a recognized annotation"));
+}
+
TEST_P(AidlTest, AcceptsOnewayMethod) {
const string oneway_method = "package a; interface IFoo { oneway void f(int a); }";
EXPECT_NE(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));