summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2013-11-22 10:32:50 -0600
committerPhilipp Haller <hallerp@gmail.com>2013-12-05 09:53:33 +0100
commit70634395a4ea6e05877704e655a5870692581ebc (patch)
tree6231ae8dfb3a0c2c9b4a0f7cfcac22b4858ec747
parent7c1d1149291e1b83c96a0f6954144b9e97c030ea (diff)
downloadscala-70634395a4ea6e05877704e655a5870692581ebc.tar.gz
scala-70634395a4ea6e05877704e655a5870692581ebc.tar.bz2
scala-70634395a4ea6e05877704e655a5870692581ebc.zip
SI-6913 Fixing semantics of Future fallbackTo to be according to docs
Origin: viktorklang@1bbe854
-rw-r--r--src/library/scala/concurrent/Future.scala5
-rw-r--r--test/files/jvm/future-spec/PromiseTests.scala4
-rw-r--r--test/files/jvm/scala-concurrent-tck.scala4
3 files changed, 8 insertions, 5 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index 39946e4472..b2c09ec53e 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -384,7 +384,10 @@ trait Future[+T] extends Awaitable[T] {
val p = Promise[U]()
onComplete {
case s @ Success(_) => p complete s
- case _ => p completeWith that
+ case f @ Failure(_) => that onComplete {
+ case s2 @ Success(_) => p complete s2
+ case _ => p complete f // Use the first failure as the failure
+ }
}
p.future
}
diff --git a/test/files/jvm/future-spec/PromiseTests.scala b/test/files/jvm/future-spec/PromiseTests.scala
index 8e07393900..48f94666ba 100644
--- a/test/files/jvm/future-spec/PromiseTests.scala
+++ b/test/files/jvm/future-spec/PromiseTests.scala
@@ -38,10 +38,10 @@ object PromiseTests extends MinimalScalaTest {
Await.result(failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
Await.result(timedOut fallbackTo empty, defaultTimeout) mustBe ("Timedout")
- Await.result(failure fallbackTo failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
+ Await.result(otherFailure fallbackTo failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
intercept[RuntimeException] {
Await.result(failure fallbackTo otherFailure, defaultTimeout)
- }.getMessage mustBe ("last")
+ }.getMessage mustBe ("br0ken")
}
}
diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala
index 6e2b8ca033..a306a7d15b 100644
--- a/test/files/jvm/scala-concurrent-tck.scala
+++ b/test/files/jvm/scala-concurrent-tck.scala
@@ -344,8 +344,8 @@ def testTransformFailure(): Unit = once {
def testFallbackToFailure(): Unit = once {
done =>
val cause = new Exception
- val f = future { sys.error("failed") }
- val g = future { throw cause }
+ val f = future { throw cause }
+ val g = future { sys.error("failed") }
val h = f fallbackTo g
h onSuccess { case _ => done(false) }