Refactor CanBeOutParameter() and error with reason
Previously, the test fails to check what we want to check.
It's fixed with an additional hint why it fails.
Bug: n/a
Test: aidl_unittests
Change-Id: Iaf09dc0a0018bc9fef63f8f484d5d8a9c687a7e9
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 82adaf8..5162960 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -1324,7 +1324,8 @@
AIDL_ERROR(m) << "oneway method '" << m->GetName() << "' cannot have out parameters";
return false;
}
- const bool can_be_out = typenames.CanBeOutParameter(arg->GetType());
+
+ const auto [can_be_out, type_aspect] = typenames.CanBeOutParameter(arg->GetType());
if (!arg->DirectionWasSpecified() && can_be_out) {
AIDL_ERROR(arg) << "'" << arg->GetType().ToString()
<< "' can be an out type, so you must declare it as in, out, or inout.";
@@ -1332,7 +1333,8 @@
}
if (arg->GetDirection() != AidlArgument::IN_DIR && !can_be_out) {
- AIDL_ERROR(arg) << "'" << arg->ToString() << "' can only be an in parameter.";
+ AIDL_ERROR(arg) << "'" << arg->GetName() << "' can't be an " << arg->GetDirectionSpecifier()
+ << " parameter because " << type_aspect << " can only be an in parameter.";
return false;
}