diff options
author | Jooyung Han <jooyung@google.com> | 2021-02-10 14:01:07 +0900 |
---|---|---|
committer | Jooyung Han <jooyung@google.com> | 2021-02-10 16:13:22 +0900 |
commit | 1d78a36f296fbc1a566fd37939df5bf4e19d8ae9 (patch) | |
tree | c404f5f94d0a856f10e671ec241ba822bd1cc86d | |
parent | a439bf67e4edc60cf9a6760d7d407c6b15b70067 (diff) | |
download | aidl-1d78a36f296fbc1a566fd37939df5bf4e19d8ae9.tar.gz |
Fix -Wmixed-oneway
Synthetic methods should be skipped when checking mixed-oneway.
Bug: none
Test: m aidl_unittests
Change-Id: Ic593e5a0aaa046ac38d93681a31e936ef7e7cad0
-rw-r--r-- | diagnostics.cpp | 16 | ||||
-rw-r--r-- | diagnostics_unittest.cpp | 12 |
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({ |