aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--diagnostics.cpp16
-rw-r--r--diagnostics_unittest.cpp12
2 files changed, 22 insertions, 6 deletions
diff --git a/diagnostics.cpp b/diagnostics.cpp
index b9138c70..baec2d76 100644
--- a/diagnostics.cpp
+++ b/diagnostics.cpp
@@ -17,7 +17,6 @@
#include <functional>
#include <stack>
-#include <unordered_set>
#include "aidl_language.h"
#include "logging.h"
@@ -192,10 +191,17 @@ struct DiagnoseExplicitDefault : DiagnosticsVisitor {
struct DiagnoseMixedOneway : DiagnosticsVisitor {
DiagnoseMixedOneway(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
void Visit(const AidlInterface& i) override {
- const auto& methods = i.GetMethods();
- if (std::adjacent_find(begin(methods), end(methods), [](const auto& a, const auto& b) {
- return a->IsOneway() != b->IsOneway();
- }) != end(methods)) {
+ bool has_oneway = false;
+ bool has_twoway = false;
+ for (const auto& m : i.GetMethods()) {
+ if (!m->IsUserDefined()) continue;
+ if (m->IsOneway()) {
+ has_oneway = true;
+ } else {
+ has_twoway = true;
+ }
+ }
+ if (has_oneway && has_twoway) {
diag.Report(i.GetLocation(), DiagnosticID::mixed_oneway)
<< "The interface '" << i.GetName() << "' has both one-way and two-way methods.";
}
diff --git a/diagnostics_unittest.cpp b/diagnostics_unittest.cpp
index 45af7772..187e7674 100644
--- a/diagnostics_unittest.cpp
+++ b/diagnostics_unittest.cpp
@@ -42,7 +42,8 @@ struct DiagnosticsTest : testing::Test {
}
// emit diagnostics as warnings.
// "java" has no specific meaning here because we're testing CheckValid()
- const Options options = Options::From("aidl -I . --lang java -o out -Weverything " + main);
+ const Options options =
+ Options::From("aidl " + optional_args + " -I . --lang java -o out -Weverything " + main);
CaptureStderr();
load_and_validate_aidl(main, options, io, &typenames, nullptr);
const std::string err = GetCapturedStderr();
@@ -57,6 +58,7 @@ struct DiagnosticsTest : testing::Test {
AidlTypenames typenames;
FakeIoDelegate io;
+ std::string optional_args;
std::vector<DiagnosticID> expect_diagnostics;
};
@@ -127,6 +129,14 @@ TEST_F(DiagnosticsTest, DontMixOnewayWithTwowayMethods) {
});
}
+TEST_F(DiagnosticsTest, OnewayInterfaceIsOkayWithSyntheticMethods) {
+ optional_args = "--version 2"; // will add getInterfaceVersion() synthetic method
+ expect_diagnostics = {};
+ ParseFiles({
+ {"IFoo.aidl", "oneway interface IFoo { void foo(); }"},
+ });
+}
+
TEST_F(DiagnosticsTest, ArraysAsOutputParametersConsideredHarmful) {
expect_diagnostics = {DiagnosticID::out_array};
ParseFiles({