In SemiFuture members, fix DCHECK of pointer types
[folly.git] / folly / futures / Future-inl.h
index 20cf87bc647a449fe462ca9b67195e3d1eecb39d..5818244cdc3443818ec8d887815eb1c8aef9c2dd 100644 (file)
@@ -473,7 +473,7 @@ void SemiFuture<T>::boost_() {
   if (auto e = this->getExecutor()) {
     // We know in a SemiFuture that if we have an executor it should be
     // DeferredExecutor. Verify this in debug mode.
-    DCHECK(dynamic_cast<DeferredExecutor*>(e));
+    DCHECK(nullptr != dynamic_cast<DeferredExecutor*>(e));
 
     auto ka = static_cast<DeferredExecutor*>(e)->getKeepAliveToken();
     static_cast<DeferredExecutor*>(e)->boost();
@@ -483,6 +483,9 @@ void SemiFuture<T>::boost_() {
 template <class T>
 inline Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && {
   throwIfInvalid();
+  if (!executor) {
+    throwNoExecutor();
+  }
 
   // If current executor is deferred, boost block to ensure that work
   // progresses and is run on the new executor.
@@ -490,7 +493,7 @@ inline Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && {
   if (oldExecutor && executor && (executor != oldExecutor)) {
     // We know in a SemiFuture that if we have an executor it should be
     // DeferredExecutor. Verify this in debug mode.
-    DCHECK(dynamic_cast<DeferredExecutor*>(this->getExecutor()));
+    DCHECK(nullptr != dynamic_cast<DeferredExecutor*>(this->getExecutor()));
     if (static_cast<DeferredExecutor*>(oldExecutor)) {
       executor->add([oldExecutorKA = oldExecutor->getKeepAliveToken()]() {
         static_cast<DeferredExecutor*>(oldExecutorKA.get())->boost();
@@ -517,7 +520,7 @@ SemiFuture<T>::defer(F&& func) && {
   // We know in a SemiFuture that if we have an executor it should be
   // DeferredExecutor (either it was that way before, or we just created it).
   // Verify this in debug mode.
-  DCHECK(dynamic_cast<DeferredExecutor*>(e));
+  DCHECK(nullptr != dynamic_cast<DeferredExecutor*>(e));
   // Convert to a folly::future with a deferred executor
   // Will be low-cost if this is not a new executor as via optimises for that
   // case