@@ -135,10 +135,8 @@ public fun <T> ListenableFuture<T>.asDeferred(): Deferred<T> {
135
135
// Finally, if this isn't done yet, attach a Listener that will complete the Deferred.
136
136
val deferred = CompletableDeferred <T >()
137
137
Futures .addCallback(this , object : FutureCallback <T > {
138
- override fun onSuccess (result : T ? ) {
139
- // Here we work with flexible types, so we unchecked cast to trick the type system
140
- @Suppress(" UNCHECKED_CAST" )
141
- runCatching { deferred.complete(result as T ) }
138
+ override fun onSuccess (result : T ) {
139
+ runCatching { deferred.complete(result) }
142
140
.onFailure { handleCoroutineException(EmptyCoroutineContext , it) }
143
141
}
144
142
@@ -351,7 +349,7 @@ private class JobListenableFuture<T>(private val jobToCancel: Job): ListenableFu
351
349
*
352
350
* To preserve Coroutine's [CancellationException], this future points to either `T` or [Cancelled].
353
351
*/
354
- private val auxFuture = SettableFuture .create<Any >()
352
+ private val auxFuture = SettableFuture .create<Any ? >()
355
353
356
354
/* *
357
355
* `true` if [auxFuture.get][ListenableFuture.get] throws [ExecutionException].
@@ -436,7 +434,7 @@ private class JobListenableFuture<T>(private val jobToCancel: Job): ListenableFu
436
434
}
437
435
438
436
/* * See [get()]. */
439
- private fun getInternal (result : Any ): T = if (result is Cancelled ) {
437
+ private fun getInternal (result : Any? ): T = if (result is Cancelled ) {
440
438
throw CancellationException ().initCause(result.exception)
441
439
} else {
442
440
// We know that `auxFuture` can contain either `T` or `Cancelled`.
0 commit comments