From 55c89e454930b986bc6e4784550f044d35f126a7 Mon Sep 17 00:00:00 2001 From: ac-patel Date: Wed, 19 Feb 2025 19:44:10 -0800 Subject: [PATCH] Change WithResult to AssertResultType for better readability. (#38743) WithResult acts as a type checker to assert that the promise passed to the function returns the expected type (i.e. Poll\). The name WithResult does not imply that the function is an assertion. Closes #38743 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38743 from ac-patel:fix_typo 4fa77b757384f0283c9c2db21038c28a55ef8902 PiperOrigin-RevId: 728914326 --- src/core/lib/promise/promise.h | 4 ++-- src/core/lib/security/transport/auth_filters.h | 2 +- test/core/promise/promise_test.cc | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/lib/promise/promise.h b/src/core/lib/promise/promise.h index 40254d93e64a7..2e6f3d4f1e127 100644 --- a/src/core/lib/promise/promise.h +++ b/src/core/lib/promise/promise.h @@ -83,12 +83,12 @@ struct ImmediateOkStatus { }; // Typecheck that a promise returns the expected return type. -// usage: auto promise = WithResult([]() { return 3; }); +// usage: auto promise = AssertResultType([]() { return 3; }); // NOTE: there are tests in promise_test.cc that are commented out because they // should fail to compile. When modifying this code these should be uncommented // and their miscompilation verified. template -GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline auto WithResult(F f) -> +GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION inline auto AssertResultType(F f) -> typename std::enable_if>::value, F>::type { return f; diff --git a/src/core/lib/security/transport/auth_filters.h b/src/core/lib/security/transport/auth_filters.h index 79e98346f14d8..2430e537c34ca 100644 --- a/src/core/lib/security/transport/auth_filters.h +++ b/src/core/lib/security/transport/auth_filters.h @@ -96,7 +96,7 @@ class ClientAuthFilter final : public ImplementChannelFilter { ClientAuthFilter* filter) { filter->InstallContext(); auto* host = md->get_pointer(HttpAuthorityMetadata()); - return WithResult>(If( + return AssertResultType>(If( host == nullptr, [&md]() mutable -> absl::StatusOr { return std::move(md); diff --git a/test/core/promise/promise_test.cc b/test/core/promise/promise_test.cc index a9f7b9ffa8a50..4b4f42c801f70 100644 --- a/test/core/promise/promise_test.cc +++ b/test/core/promise/promise_test.cc @@ -28,10 +28,10 @@ TEST(PromiseTest, Works) { TEST(PromiseTest, Immediate) { EXPECT_EQ(Immediate(42)(), Poll(42)); } -TEST(PromiseTest, WithResult) { - EXPECT_EQ(WithResult(Immediate(42))(), Poll(42)); - // Fails to compile: WithResult(Immediate(std::string("hello"))); - // Fails to compile: WithResult(Immediate(42.9)); +TEST(PromiseTest, AssertResultType) { + EXPECT_EQ(AssertResultType(Immediate(42))(), Poll(42)); + // Fails to compile: AssertResultType(Immediate(std::string("hello"))); + // Fails to compile: AssertResultType(Immediate(42.9)); } TEST(PromiseTest, NowOrNever) {