(Wangle) Swap order of Try<T> and T matching
authorHannes Roth <hannesr@fb.com>
Thu, 2 Apr 2015 04:31:29 +0000 (21:31 -0700)
committerafrind <afrind@fb.com>
Thu, 2 Apr 2015 19:02:29 +0000 (12:02 -0700)
Summary:
See the test case and D1958860.

I don't really know why I chose one over the other. This fixes a bug. So
it's better?

Test Plan: Run all the tests?

Reviewed By: yfeldblum@fb.com

Subscribers: folly-diffs@, jsedgwick, yfeldblum, chalfant, over

FB internal diff: D1960740

Signature: t1:1960740:1427927644:25093b049a1519d7c869ee7043f3caced4cc971e

folly/futures/Future.h
folly/futures/test/FutureTest.cpp

index f507748df2aee09da78b0b903aeda78d445d0ab1..18649726f3e91f4586dd6fdacfdf3a9937e0fe76 100644 (file)
@@ -99,15 +99,15 @@ struct callableResult {
     callableWith<F>::value,
     detail::argResult<false, F>,
     typename std::conditional<
-      callableWith<F, Try<T>&&>::value,
-      detail::argResult<true, F, Try<T>&&>,
+      callableWith<F, T&&>::value,
+      detail::argResult<false, F, T&&>,
       typename std::conditional<
-        callableWith<F, Try<T>&>::value,
-        detail::argResult<true, F, Try<T>&>,
+        callableWith<F, T&>::value,
+        detail::argResult<false, F, T&>,
         typename std::conditional<
-          callableWith<F, T&&>::value,
-          detail::argResult<false, F, T&&>,
-          detail::argResult<false, F, T&>>::type>::type>::type>::type Arg;
+          callableWith<F, Try<T>&&>::value,
+          detail::argResult<true, F, Try<T>&&>,
+          detail::argResult<true, F, Try<T>&>>::type>::type>::type>::type Arg;
   typedef isFuture<typename Arg::Result> ReturnsFuture;
   typedef Future<typename ReturnsFuture::Inner> Return;
 };
index 3da4dcfb7ee3a17ca7788566b33754f278e9785b..5a38c18b4d4468d86dcc5f198847a34332cc21ed 100644 (file)
@@ -28,6 +28,7 @@
 #include <folly/futures/Future.h>
 #include <folly/futures/ManualExecutor.h>
 #include <folly/futures/DrivableExecutor.h>
+#include <folly/dynamic.h>
 #include <folly/MPMCQueue.h>
 
 #include <folly/io/async/EventBase.h>
@@ -1311,6 +1312,20 @@ TEST(Future, ImplicitConstructor) {
   //auto f2 = []() -> Future<void> { }();
 }
 
+TEST(Future, thenDynamic) {
+  // folly::dynamic has a constructor that takes any T, this test makes
+  // sure that we call the then lambda with folly::dynamic and not
+  // Try<folly::dynamic> because that then fails to compile
+  Promise<folly::dynamic> p;
+  Future<folly::dynamic> f = p.getFuture().then(
+      [](const folly::dynamic& d) {
+        return folly::dynamic(d.asInt() + 3);
+      }
+  );
+  p.setValue(2);
+  EXPECT_EQ(f.get(), 5);
+}
+
 TEST(Future, via_then_get_was_racy) {
   ThreadExecutor x;
   std::unique_ptr<int> val = folly::via(&x)