Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapping futures succeeds typecheck when it shouldn't #9822

Closed
scabug opened this issue Jun 17, 2016 · 3 comments
Closed

mapping futures succeeds typecheck when it shouldn't #9822

scabug opened this issue Jun 17, 2016 · 3 comments

Comments

@scabug
Copy link

scabug commented Jun 17, 2016

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

  def future1: Future[Unit] = Future.successful(())
  def future2: Future[Unit] = Future.successful(())

  def test: Future[Unit] = future1.map { _ => future2 }

the body of the test function returns Future[Future[Unit]], however, the compiler is happy to say that it is simply a Future[Unit], which leads to errors in code

@scabug
Copy link
Author

scabug commented Jun 17, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9822?orig=1
Reporter: Sarunas Valaskevicius (rakatan)
Affected Versions: 2.11.7

@scabug
Copy link
Author

scabug commented Jun 17, 2016

@som-snytt said:
There's an option for that:

$ scala -Ywarn-value-discard
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> import concurrent._, ExecutionContext.Implicits._
import concurrent._
import ExecutionContext.Implicits._

scala> def f1 = Future.successful(())
f1: scala.concurrent.Future[Unit]

scala> def f2 = Future.successful(())
f2: scala.concurrent.Future[Unit]

scala> f1 map (_ => f2)
res0: scala.concurrent.Future[scala.concurrent.Future[Unit]] = Success(scala.concurrent.impl.Promise$KeptPromise@258e2e41)

scala> def f3: Future[Unit] = f1 map (_ => f2)
<console>:19: warning: discarded non-Unit value
       def f3: Future[Unit] = f1 map (_ => f2)
                                           ^
f3: scala.concurrent.Future[Unit]

Include -Xfatal-warnings to lock it down.

@scabug
Copy link
Author

scabug commented Jun 17, 2016

Sarunas Valaskevicius (rakatan) said:
Ah right, will add it to the set of my default options, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant