diff options
Diffstat (limited to 'test/files')
45 files changed, 766 insertions, 62 deletions
diff --git a/test/files/jvm/future-spec.check b/test/files/jvm/future-spec.check index df1629dd7e..5c80aa5586 100644 --- a/test/files/jvm/future-spec.check +++ b/test/files/jvm/future-spec.check @@ -1 +1 @@ -warning: there was one deprecation warning; re-run with -deprecation for details +warning: there were 21 deprecation warnings; re-run with -deprecation for details diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index a290af9cd3..6b34d5bfaa 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -17,6 +17,19 @@ class FutureTests extends MinimalScalaTest { case "NoReply" => Promise[String]().future } + def fail(msg: String): Nothing = throw new AssertionError(msg) + + def ECNotUsed[T](f: ExecutionContext => T): T = { + val p = Promise[Runnable]() + val unusedEC: ExecutionContext = new ExecutionContext { + def execute(r: Runnable) = p.success(r) + def reportFailure(t: Throwable): Unit = p.failure(t) + } + val t = f(unusedEC) + assert(p.future.value == None, "Future executed logic!") + t + } + val defaultTimeout = 5 seconds /* future specification */ @@ -68,6 +81,60 @@ class FutureTests extends MinimalScalaTest { } } + "Futures" should { + "have proper toString representations" in { + import ExecutionContext.Implicits.global + val s = 5 + val f = new Exception("foo") + val t = Try(throw f) + + val expectFailureString = "Future(Failure("+f+"))" + val expectSuccessString = "Future(Success(5))" + val expectNotCompleteString = "Future(<not completed>)" + + Future.successful(s).toString mustBe expectSuccessString + Future.failed(f).toString mustBe expectFailureString + Future.fromTry(t).toString mustBe expectFailureString + val p = Promise[Int]() + p.toString mustBe expectNotCompleteString + Promise[Int]().success(s).toString mustBe expectSuccessString + Promise[Int]().failure(f).toString mustBe expectFailureString + Await.ready(Future { throw f }, 2000 millis).toString mustBe expectFailureString + Await.ready(Future { s }, 2000 millis).toString mustBe expectSuccessString + + Future.never.toString mustBe "Future(<never>)" + Future.unit.toString mustBe "Future(Success(()))" + } + + "have proper const representation for success" in { + val s = "foo" + val f = Future.successful(s) + + ECNotUsed(ec => f.onFailure({ case _ => fail("onFailure should not have been called") })(ec)) + assert( ECNotUsed(ec => f.recover({ case _ => fail("recover should not have been called")})(ec)) eq f) + assert( ECNotUsed(ec => f.recoverWith({ case _ => fail("flatMap should not have been called")})(ec)) eq f) + assert(f.fallbackTo(f) eq f, "Future.fallbackTo must be the same instance as Future.fallbackTo") + } + + "have proper const representation for failure" in { + val e = new Exception("foo") + val f = Future.failed[Future[String]](e) + + assert(f.mapTo[String] eq f, "Future.mapTo must be the same instance as Future.mapTo") + assert(f.zip(f) eq f, "Future.zip must be the same instance as Future.zip") + assert(f.flatten eq f, "Future.flatten must be the same instance as Future.flatten") + assert(f.failed eq f, "Future.failed must be the same instance as Future.failed") + + ECNotUsed(ec => f.foreach(_ => fail("foreach should not have been called"))(ec)) + ECNotUsed(ec => f.onSuccess({ case _ => fail("onSuccess should not have been called") })(ec)) + assert( ECNotUsed(ec => f.map(_ => fail("map should not have been called"))(ec)) eq f) + assert( ECNotUsed(ec => f.flatMap(_ => fail("flatMap should not have been called"))(ec)) eq f) + assert( ECNotUsed(ec => f.filter(_ => fail("filter should not have been called"))(ec)) eq f) + assert( ECNotUsed(ec => f.collect({ case _ => fail("collect should not have been called")})(ec)) eq f) + assert( ECNotUsed(ec => f.zipWith(f)({ (_,_) => fail("zipWith should not have been called")})(ec)) eq f) + } + } + "The Future companion object" should { "call ExecutionContext.prepare on apply" in { val p = Promise[Boolean]() @@ -85,6 +152,49 @@ class FutureTests extends MinimalScalaTest { Await.result(f, defaultTimeout) mustBe ("foo") Await.result(p.future, defaultTimeout) mustBe (true) } + + "have a unit member representing an already completed Future containing Unit" in { + assert(Future.unit ne null, "Future.unit must not be null") + assert(Future.unit eq Future.unit, "Future.unit must be the same instance as Future.unit") + assert(Future.unit.isCompleted, "Future.unit must already be completed") + assert(Future.unit.value.get == Success(()), "Future.unit must contain a Success(())") + } + + "have a never member representing a never completed Future of Nothing" in { + + val test: Future[Nothing] = Future.never + + //Verify stable identifier + test match { + case Future.`never` => + case _ => fail("Future.never did not match Future.`never`") + } + + assert(test eq Future.never, "Future.never must be the same instance as Future.never") + assert(test ne null, "Future.never must not be null") + assert(!test.isCompleted && test.value.isEmpty, "Future.never must never be completed") + assert(test.failed eq test) + assert(test.asInstanceOf[Future[Future[Nothing]]].flatten eq test) + assert(test.zip(test) eq test) + assert(test.fallbackTo(test) eq test) + assert(test.mapTo[String] eq test) + + ECNotUsed(ec => test.foreach(_ => fail("foreach should not have been called"))(ec)) + ECNotUsed(ec => test.onSuccess({ case _ => fail("onSuccess should not have been called") })(ec)) + ECNotUsed(ec => test.onFailure({ case _ => fail("onFailure should not have been called") })(ec)) + ECNotUsed(ec => test.onComplete({ case _ => fail("onComplete should not have been called") })(ec)) + ECNotUsed(ec => test.transform(identity, identity)(ec) eq test) + ECNotUsed(ec => test.transform(identity)(ec) eq test) + ECNotUsed(ec => test.transformWith(_ => fail("transformWith should not have been called"))(ec) eq test) + ECNotUsed(ec => test.map(identity)(ec) eq test) + ECNotUsed(ec => test.flatMap(_ => fail("flatMap should not have been called"))(ec) eq test) + ECNotUsed(ec => test.filter(_ => fail("filter should not have been called"))(ec) eq test) + ECNotUsed(ec => test.collect({ case _ => fail("collect should not have been called")})(ec) eq test) + ECNotUsed(ec => test.recover({ case _ => fail("recover should not have been called")})(ec) eq test) + ECNotUsed(ec => test.recoverWith({ case _ => fail("recoverWith should not have been called")})(ec) eq test) + ECNotUsed(ec => test.andThen({ case _ => fail("andThen should not have been called")})(ec) eq test) + ECNotUsed(ec => test.zipWith(test)({ (_,_) => fail("zipWith should not have been called")})(ec) eq test) + } } "The default ExecutionContext" should { @@ -218,6 +328,142 @@ class FutureTests extends MinimalScalaTest { } mustBe (r) } + "transform results to results" in { + val f1 = Future.successful("foo").transform(_.map(_.toUpperCase)) + val f2 = Future("bar").transform(_.map(_.toUpperCase)) + Await.result(f1, defaultTimeout) mustBe "FOO" + Await.result(f2, defaultTimeout) mustBe "BAR" + } + + "transform failures to failures" in { + val initial = new Exception("Initial") + val expected1 = new Exception("Expected1") + val expected2 = new Exception("Expected2") + val f1 = Future(throw initial) transform { + case Failure(`initial`) => Failure(expected1) + case x => x + } + val f2 = Future.failed(initial) transform { + case Failure(`initial`) => Failure(expected2) + case x => x + } + + intercept[Exception] { Await.result(f1, defaultTimeout) } mustBe expected1 + intercept[Exception] { Await.result(f2, defaultTimeout) } mustBe expected2 + } + + "transform failures to results" in { + val initial1 = new Exception("Initial1") + val initial2 = new Exception("Initial2") + val f1 = Future.failed[String](initial1) transform { + case Failure(`initial1`) => Success("foo") + case x => x + } + val f2 = Future[String](throw initial2) transform { + case Failure(`initial2`) => Success("bar") + case x => x + } + Await.result(f1, defaultTimeout) mustBe "foo" + Await.result(f2, defaultTimeout) mustBe "bar" + } + + "transform results to failures" in { + val expected1 = new Exception("Expected1") + val expected2 = new Exception("Expected2") + val expected3 = new Exception("Expected3") + val f1 = Future.successful("foo") transform { + case Success("foo") => Failure(expected1) + case x => x + } + val f2 = Future("bar") transform { + case Success("bar") => Failure(expected2) + case x => x + } + val f3 = Future("bar") transform { + case Success("bar") => throw expected3 + case x => x + } + intercept[Exception] { Await.result(f1, defaultTimeout) } mustBe expected1 + intercept[Exception] { Await.result(f2, defaultTimeout) } mustBe expected2 + intercept[Exception] { Await.result(f3, defaultTimeout) } mustBe expected3 + } + + "transformWith results" in { + val f1 = Future.successful("foo").transformWith { + case Success(r) => Future(r.toUpperCase) + case f @ Failure(_) => Future.fromTry(f) + } + val f2 = Future("bar").transformWith { + case Success(r) => Future(r.toUpperCase) + case f @ Failure(_) => Future.fromTry(f) + } + Await.result(f1, defaultTimeout) mustBe "FOO" + Await.result(f2, defaultTimeout) mustBe "BAR" + } + + "transformWith failures" in { + val initial = new Exception("Initial") + val expected1 = new Exception("Expected1") + val expected2 = new Exception("Expected2") + val expected3 = new Exception("Expected3") + + val f1 = Future[Int](throw initial).transformWith { + case Failure(`initial`) => Future failed expected1 + case x => Future fromTry x + } + val f2 = Future.failed[Int](initial).transformWith { + case Failure(`initial`) => Future failed expected2 + case x => Future fromTry x + } + val f3 = Future[Int](throw initial).transformWith { + case Failure(`initial`) => throw expected3 + case x => Future fromTry x + } + + intercept[Exception] { Await.result(f1, defaultTimeout) } mustBe expected1 + intercept[Exception] { Await.result(f2, defaultTimeout) } mustBe expected2 + intercept[Exception] { Await.result(f3, defaultTimeout) } mustBe expected3 + } + + "transformWith failures to future success" in { + val initial = new Exception("Initial") + val f1 = Future.failed[String](initial).transformWith { + case Failure(`initial`) => Future("FOO") + case _ => Future failed initial + } + val f2 = Future[String](throw initial).transformWith { + case Failure(`initial`) => Future("BAR") + case _ => Future failed initial + } + Await.result(f1, defaultTimeout) mustBe "FOO" + Await.result(f2, defaultTimeout) mustBe "BAR" + } + + "transformWith results to future failures" in { + val initial = new Exception("Initial") + val expected1 = new Exception("Expected1") + val expected2 = new Exception("Expected2") + val expected3 = new Exception("Expected3") + + val f1 = Future[String]("FOO") transformWith { + case Success("FOO") => Future failed expected1 + case _ => Future successful "FOO" + } + val f2 = Future.successful("FOO") transformWith { + case Success("FOO") => Future failed expected2 + case _ => Future successful "FOO" + } + val f3 = Future.successful("FOO") transformWith { + case Success("FOO") => throw expected3 + case _ => Future successful "FOO" + } + + + intercept[Exception] { Await.result(f1, defaultTimeout) } mustBe expected1 + intercept[Exception] { Await.result(f2, defaultTimeout) } mustBe expected2 + intercept[Exception] { Await.result(f3, defaultTimeout) } mustBe expected3 + } + "andThen like a boss" in { val q = new java.util.concurrent.LinkedBlockingQueue[Int] for (i <- 1 to 1000) { @@ -281,6 +527,33 @@ class FutureTests extends MinimalScalaTest { Await.result(successful, timeout) mustBe (("foo", "foo")) } + "zipWith" in { + val timeout = 10000 millis + val f = new IllegalStateException("test") + intercept[IllegalStateException] { + val failed = Future.failed[String](f).zipWith(Future.successful("foo")) { _ -> _ } + Await.result(failed, timeout) + } mustBe (f) + + intercept[IllegalStateException] { + val failed = Future.successful("foo").zipWith(Future.failed[String](f)) { _ -> _ } + Await.result(failed, timeout) + } mustBe (f) + + intercept[IllegalStateException] { + val failed = Future.failed[String](f).zipWith(Future.failed[String](f)) { _ -> _ } + Await.result(failed, timeout) + } mustBe (f) + + val successful = Future.successful("foo").zipWith(Future.successful("foo")) { _ -> _ } + Await.result(successful, timeout) mustBe (("foo", "foo")) + + val failure = Future.successful("foo").zipWith(Future.successful("foo")) { (_,_) => throw f } + intercept[IllegalStateException] { + Await.result(failure, timeout) + } mustBe (f) + } + "fold" in { val timeout = 10000 millis def async(add: Int, wait: Int) = Future { diff --git a/test/files/jvm/scala-concurrent-tck.check b/test/files/jvm/scala-concurrent-tck.check new file mode 100644 index 0000000000..bbe73c9982 --- /dev/null +++ b/test/files/jvm/scala-concurrent-tck.check @@ -0,0 +1 @@ +warning: there were 74 deprecation warnings; re-run with -deprecation for details diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index ce86d4aef0..ba405e97bd 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -165,6 +165,100 @@ def testTransformFailure(): Unit = once { g onFailure { case e => done(e eq transformed) } } + def testTransformResultToResult(): Unit = once { + done => + Future("foo").transform { + case Success(s) => Success(s.toUpperCase) + case Failure(f) => throw new Exception("test failed") + } onComplete { + case Success("FOO") => done(true) + case _ => done(false) + } + } + + def testTransformResultToFailure(): Unit = once { + done => + val e = new Exception("expected") + Future("foo").transform { + case Success(s) => Failure(e) + case Failure(f) => throw new Exception("test failed") + } onComplete { + case Failure(`e`) => done(true) + case _ => done(false) + } + } + + def testTransformFailureToResult(): Unit = once { + done => + val e = "foo" + Future(throw new Exception("initial")).transform { + case Success(s) => throw new Exception("test failed") + case Failure(f) => Success(e) + } onComplete { + case Success(`e`) => done(true) + case _ => done(false) + } + } + + def testTransformFailureToFailure(): Unit = once { + done => + val e = new Exception("expected") + Future(throw new Exception("initial")).transform { + case Success(s) => throw new Exception("test failed") + case Failure(f) => Failure(e) + } onComplete { + case Failure(`e`) => done(true) + case _ => done(false) + } + } + + def testTransformWithResultToResult(): Unit = once { + done => + Future("foo").transformWith { + case Success(s) => Future(s.toUpperCase) + case Failure(f) => throw new Exception("test failed") + } onComplete { + case Success("FOO") => done(true) + case _ => done(false) + } + } + + def testTransformWithResultToFailure(): Unit = once { + done => + val e = new Exception("expected") + Future("foo").transformWith { + case Success(s) => Future(throw e) + case Failure(f) => throw new Exception("test failed") + } onComplete { + case Failure(`e`) => done(true) + case _ => done(false) + } + } + + def testTransformWithFailureToResult(): Unit = once { + done => + val e = "foo" + Future(throw new Exception("initial")).transformWith { + case Success(s) => throw new Exception("test failed") + case Failure(f) => Future(e) + } onComplete { + case Success(`e`) => done(true) + case _ => done(false) + } + } + + def testTransformWithFailureToFailure(): Unit = once { + done => + val e = new Exception("expected") + Future(throw new Exception("initial")).transformWith { + case Success(s) => throw new Exception("test failed") + case Failure(f) => Future(throw e) + } onComplete { + case Failure(`e`) => done(true) + case _ => done(false) + } + } + def testFoldFailure(): Unit = once { done => val f = Future[Unit] { throw new Exception("expected") } @@ -352,6 +446,14 @@ def testTransformFailure(): Unit = once { h onFailure { case e => done(e eq cause) } } + def testFallbackToThis(): Unit = { + def check(f: Future[Int]) = assert((f fallbackTo f) eq f) + + check(Future { 1 }) + check(Future.successful(1)) + check(Future.failed[Int](new Exception)) + } + testMapSuccess() testMapFailure() testFlatMapSuccess() @@ -373,6 +475,16 @@ def testTransformFailure(): Unit = once { testFallbackToFailure() testTransformSuccess() testTransformSuccessPF() + testTransformFailure() + testTransformFailurePF() + testTransformResultToResult() + testTransformResultToFailure() + testTransformFailureToResult() + testTransformFailureToFailure() + testTransformWithResultToResult() + testTransformWithResultToFailure() + testTransformWithFailureToResult() + testTransformWithFailureToFailure() } @@ -593,6 +705,17 @@ trait Exceptions extends TestBase { } +trait GlobalExecutionContext extends TestBase { + def testNameOfGlobalECThreads(): Unit = once { + done => Future({ + val expectedName = "scala-execution-context-global-"+ Thread.currentThread.getId + done(expectedName == Thread.currentThread.getName) + })(ExecutionContext.global) + } + + testNameOfGlobalECThreads() +} + trait CustomExecutionContext extends TestBase { import scala.concurrent.{ ExecutionContext, Awaitable } @@ -772,6 +895,7 @@ with FutureProjections with Promises with BlockContexts with Exceptions +with GlobalExecutionContext with CustomExecutionContext with ExecutionContextPrepare { diff --git a/test/files/jvm/t7146.scala b/test/files/jvm/t7146.scala index aaa3dc7ca4..ea734472d5 100644 --- a/test/files/jvm/t7146.scala +++ b/test/files/jvm/t7146.scala @@ -10,7 +10,7 @@ object Test { ExecutionContext.global.toString.startsWith("scala.concurrent.impl.ExecutionContextImpl")) val i = ExecutionContext.global.asInstanceOf[{ def executor: Executor }] println("should be scala.concurrent.forkjoin.ForkJoinPool == " + - i.executor.toString.startsWith("scala.concurrent.forkjoin.ForkJoinPool")) + (i.executor.getClass.getSuperclass.getName == "scala.concurrent.forkjoin.ForkJoinPool")) val u = i.executor. asInstanceOf[{ def getUncaughtExceptionHandler: Thread.UncaughtExceptionHandler }]. getUncaughtExceptionHandler diff --git a/test/files/jvm/t8582.check b/test/files/jvm/t8582.check index 564f482ff8..1d19f1d6a8 100644 --- a/test/files/jvm/t8582.check +++ b/test/files/jvm/t8582.check @@ -1,3 +1,6 @@ +t8582.scala:17: warning: class BeanInfo in package beans is deprecated: the generation of BeanInfo classes is no longer supported + class C1 + ^ getClass on module gives module class class p1.p2.Singleton$Singleton$ diff --git a/test/files/jvm/t8582.flags b/test/files/jvm/t8582.flags new file mode 100644 index 0000000000..dcc59ebe32 --- /dev/null +++ b/test/files/jvm/t8582.flags @@ -0,0 +1 @@ +-deprecation diff --git a/test/files/neg/beanInfoDeprecation.check b/test/files/neg/beanInfoDeprecation.check new file mode 100644 index 0000000000..788b277818 --- /dev/null +++ b/test/files/neg/beanInfoDeprecation.check @@ -0,0 +1,6 @@ +beanInfoDeprecation.scala:2: warning: class BeanInfo in package beans is deprecated: the generation of BeanInfo classes is no longer supported +class C + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/test/files/neg/beanInfoDeprecation.flags b/test/files/neg/beanInfoDeprecation.flags new file mode 100644 index 0000000000..c6bfaf1f64 --- /dev/null +++ b/test/files/neg/beanInfoDeprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/test/files/neg/beanInfoDeprecation.scala b/test/files/neg/beanInfoDeprecation.scala new file mode 100644 index 0000000000..c7e3a86202 --- /dev/null +++ b/test/files/neg/beanInfoDeprecation.scala @@ -0,0 +1,2 @@ +@scala.beans.BeanInfo +class C diff --git a/test/files/neg/t8764.check b/test/files/neg/t8764.check deleted file mode 100644 index 6d89ebe106..0000000000 --- a/test/files/neg/t8764.check +++ /dev/null @@ -1,6 +0,0 @@ -t8764.scala:8: error: type mismatch; - found : AnyVal - required: Double - val d: Double = a.productElement(0) - ^ -one error found diff --git a/test/files/neg/t8764.flags b/test/files/neg/t8764.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/neg/t8764.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/neg/t8764.scala b/test/files/neg/t8764.scala deleted file mode 100644 index dc5bfb0160..0000000000 --- a/test/files/neg/t8764.scala +++ /dev/null @@ -1,9 +0,0 @@ -object Main { - - case class IntAndDouble(i: Int, d: Double) - - // a.productElement used to be Int => Double - // now: Int => AnyVal - val a = IntAndDouble(1, 5.0) - val d: Double = a.productElement(0) -} diff --git a/test/files/neg/t8849.check b/test/files/neg/t8849.check new file mode 100644 index 0000000000..15b00aee8b --- /dev/null +++ b/test/files/neg/t8849.check @@ -0,0 +1,7 @@ +t8849.scala:8: error: ambiguous implicit values: + both value global in object Implicits of type => scala.concurrent.ExecutionContext + and value dummy of type scala.concurrent.ExecutionContext + match expected type scala.concurrent.ExecutionContext + require(implicitly[ExecutionContext] eq dummy) + ^ +one error found diff --git a/test/files/neg/t8849.scala b/test/files/neg/t8849.scala new file mode 100644 index 0000000000..336f16b40f --- /dev/null +++ b/test/files/neg/t8849.scala @@ -0,0 +1,10 @@ +import scala.concurrent.ExecutionContext +import ExecutionContext.Implicits.global + +object Test { + def main(args: Array[String]): Unit = { + implicit val dummy: ExecutionContext = null + require(scala.concurrent.ExecutionContext.Implicits.global ne null) + require(implicitly[ExecutionContext] eq dummy) + } +}
\ No newline at end of file diff --git a/test/files/pos/alladin763.scala b/test/files/pos/alladin763.scala new file mode 100644 index 0000000000..29c9b25318 --- /dev/null +++ b/test/files/pos/alladin763.scala @@ -0,0 +1,37 @@ +// Test from http://lrytz.github.io/scala-aladdin-bugtracker/displayItem.do%3Fid=763.html +// and expanded with package object variants + + +trait Foo { type T; def apply() : T } +object e extends Foo { type T = Int; def apply() = 42 } + +package p { + trait T[X] { def O : { def apply(): X } } + object `package` extends T[Int] { + def O: { def apply(): Int } = new { def apply(): Int = 42 } + } + + object Test { + val x: Int = O() + } +} + +object Test { + + val f = new Foo { type T = Int; def apply() = 42 } + + def main(args: Array[String]): Unit = { + val g = new Foo { type T = Int; def apply() = 42 } + + (e: Foo)() + val ee: Int = e() + + (f: Foo)() + val ff: Int = f() + + (g: Foo)() + val gg: Int = g() + + val pp: Int = p.O() + } +} diff --git a/test/files/pos/t8462.scala b/test/files/pos/t8462.scala new file mode 100644 index 0000000000..6946cf8e5e --- /dev/null +++ b/test/files/pos/t8462.scala @@ -0,0 +1,11 @@ + +trait ConstantOps { + def exprs = ( + 1 << 2L : Int, // was: error: type mismatch; found : Long(4L) + 64 >> 2L : Int, // was: error: type mismatch; found : Long(4L) + 64 >>> 2L : Int, // was: error: type mismatch; found : Long(4L) + 'a' << 2L : Int, + 'a' >> 2L : Int, + 'a'>>> 2L : Int + ) +} diff --git a/test/files/pos/t8862a.scala b/test/files/pos/t8862a.scala new file mode 100644 index 0000000000..f9576707ba --- /dev/null +++ b/test/files/pos/t8862a.scala @@ -0,0 +1,47 @@ +package p { + + abstract class C[A] { + def x: A + implicit def oops: A = x + implicit def oopso: Option[A] = None + } + + package q { + + class Oops + + object `package` extends C[Oops] { + override def x = new Oops + } + + object Blah { + oops + oopso + + // implicits found in enclosing context + implicitly[Oops] + implicitly[Option[Oops]] + } + } +} + +package other { + + object Blah { + // implicits found through this import + import p.q._ + + oops + oopso + + implicitly[Oops] + implicitly[Option[Oops]] + } + + + object Blee { + // implicits found through the companion implicits + implicitly[p.q.Oops] + implicitly[Option[p.q.Oops]] + } +} diff --git a/test/files/pos/t8862b.scala b/test/files/pos/t8862b.scala new file mode 100644 index 0000000000..8be7fb5fab --- /dev/null +++ b/test/files/pos/t8862b.scala @@ -0,0 +1,12 @@ +package p { + trait T[X] { def O : { def apply(): X } } + object `package` extends T[Int] { + def O: { def apply(): Int } = new { def apply(): Int = 42 } + } + + object Test { + def main(args: Array[String]): Unit = { + val x: Int = O() + } + } +} diff --git a/test/files/run/future-flatmap-exec-count.check b/test/files/run/future-flatmap-exec-count.check index dd9dce64ed..7065c133e0 100644 --- a/test/files/run/future-flatmap-exec-count.check +++ b/test/files/run/future-flatmap-exec-count.check @@ -1,3 +1,4 @@ +warning: there was one deprecation warning; re-run with -deprecation for details mapping execute() flatmapping diff --git a/test/files/run/inline-ex-handlers.check b/test/files/run/inline-ex-handlers.check index 7c885d2cc9..27a277d314 100644 --- a/test/files/run/inline-ex-handlers.check +++ b/test/files/run/inline-ex-handlers.check @@ -123,12 +123,12 @@ 300 RETURN(UNIT) @@ -583,6 +603,6 @@ with finalizer: null -- catch (Throwable) in ArrayBuffer(7, 9, 10) starting at: 6 -+ catch (Throwable) in ArrayBuffer(7, 9, 10, 11) starting at: 6 +- catch (Throwable) in Vector(7, 9, 10) starting at: 6 ++ catch (Throwable) in Vector(7, 9, 10, 11) starting at: 6 consisting of blocks: List(6) with finalizer: null -- catch (Throwable) in ArrayBuffer(4, 6, 7, 9, 10) starting at: 3 -+ catch (Throwable) in ArrayBuffer(4, 6, 7, 9, 10, 11, 12) starting at: 3 +- catch (Throwable) in Vector(4, 6, 7, 9, 10) starting at: 3 ++ catch (Throwable) in Vector(4, 6, 7, 9, 10, 11, 12) starting at: 3 consisting of blocks: List(3) @@ -618,3 +638,3 @@ startBlock: 1 @@ -171,8 +171,8 @@ } @@ -690,3 +730,3 @@ with finalizer: null -- catch (<none>) in ArrayBuffer(4, 5, 6, 8) starting at: 3 -+ catch (<none>) in ArrayBuffer(4, 5, 6, 8, 10) starting at: 3 +- catch (<none>) in Vector(4, 5, 6, 8) starting at: 3 ++ catch (<none>) in Vector(4, 5, 6, 8, 10) starting at: 3 consisting of blocks: List(3) @@ -714,5 +754,5 @@ def main(args: Array[String] (ARRAY[REF(class String)])): Unit { @@ -276,12 +276,12 @@ } @@ -852,6 +918,6 @@ with finalizer: null -- catch (Throwable) in ArrayBuffer(13, 14, 15, 18, 20, 21, 23) starting at: 4 -+ catch (Throwable) in ArrayBuffer(13, 14, 15, 18, 20, 21, 23, 25) starting at: 4 +- catch (Throwable) in Vector(13, 14, 15, 18, 20, 21, 23) starting at: 4 ++ catch (Throwable) in Vector(13, 14, 15, 18, 20, 21, 23, 25) starting at: 4 consisting of blocks: List(9, 8, 6, 5, 4) with finalizer: null -- catch (<none>) in ArrayBuffer(4, 5, 6, 9, 13, 14, 15, 18, 20, 21, 23) starting at: 3 -+ catch (<none>) in ArrayBuffer(4, 5, 6, 9, 13, 14, 15, 18, 20, 21, 23, 25, 26) starting at: 3 +- catch (<none>) in Vector(4, 5, 6, 9, 13, 14, 15, 18, 20, 21, 23) starting at: 3 ++ catch (<none>) in Vector(4, 5, 6, 9, 13, 14, 15, 18, 20, 21, 23, 25, 26) starting at: 3 consisting of blocks: List(3) @@ -879,5 +945,5 @@ def main(args: Array[String] (ARRAY[REF(class String)])): Unit { @@ -317,8 +317,8 @@ 127 CALL_METHOD scala.Predef.println (dynamic) @@ -964,3 +1034,3 @@ with finalizer: null -- catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 13, 14, 16) starting at: 3 -+ catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 13, 14, 16, 17) starting at: 3 +- catch (IllegalArgumentException) in Vector(6, 7, 8, 11, 13, 14, 16) starting at: 3 ++ catch (IllegalArgumentException) in Vector(6, 7, 8, 11, 13, 14, 16, 17) starting at: 3 consisting of blocks: List(3) @@ -988,5 +1058,5 @@ def main(args: Array[String] (ARRAY[REF(class String)])): Unit { diff --git a/test/files/run/lub-visibility.check b/test/files/run/lub-visibility.check index 70734966f0..135cb3cb76 100644 --- a/test/files/run/lub-visibility.check +++ b/test/files/run/lub-visibility.check @@ -6,6 +6,6 @@ scala> // should infer List[scala.collection.immutable.Seq[Nothing]] scala> // but reverted that for SI-5534. scala> val x = List(List(), Vector()) -x: List[scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing] with java.io.Serializable] = List(List(), Vector()) +x: List[scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing] with Serializable] = List(List(), Vector()) scala> :quit diff --git a/test/files/run/t2251b.check b/test/files/run/t2251b.check index 4231fc6ea6..b60698d605 100644 --- a/test/files/run/t2251b.check +++ b/test/files/run/t2251b.check @@ -1,4 +1,4 @@ -TypeTag[List[scala.collection.immutable.LinearSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with scala.collection.AbstractSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with java.io.Serializable]] +TypeTag[List[scala.collection.immutable.LinearSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with scala.collection.AbstractSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with Serializable]] TypeTag[List[scala.collection.immutable.Iterable[B[_ >: F with E with D with C <: B[_ >: F with E with D with C <: A]]] with F with Int => Any]] TypeTag[List[scala.collection.immutable.Seq[B[_ >: D with C <: B[_ >: D with C <: A]]] with scala.collection.AbstractSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with Serializable]] TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G with F <: A]]]]] @@ -6,6 +6,6 @@ TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G w TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G with F <: A]]]]] TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]] TypeTag[List[scala.collection.Map[_ >: F with C <: B[_ >: F with C <: B[_ >: F with C <: A]], B[_ >: G with D <: B[_ >: G with D <: A]]]]] -TypeTag[List[scala.collection.AbstractSeq[B[_ >: G with F <: B[_ >: G with F <: A]]] with scala.collection.LinearSeq[B[_ >: G with F <: B[_ >: G with F <: A]]] with java.io.Serializable]] +TypeTag[List[scala.collection.AbstractSeq[B[_ >: G with F <: B[_ >: G with F <: A]]] with scala.collection.LinearSeq[B[_ >: G with F <: B[_ >: G with F <: A]]] with Serializable]] TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]] TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]] diff --git a/test/files/run/t4332.scala b/test/files/run/t4332.scala index 5a67922911..1c7e7d73de 100644 --- a/test/files/run/t4332.scala +++ b/test/files/run/t4332.scala @@ -12,7 +12,7 @@ object Test extends DirectTest { } def isExempt(sym: Symbol) = { - val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform") + val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform", "filterImpl") (exempt contains sym.name.decoded) } diff --git a/test/files/run/t6827.check b/test/files/run/t6827.check index 3a3a71c67d..4889e05be8 100644 --- a/test/files/run/t6827.check +++ b/test/files/run/t6827.check @@ -1,6 +1,6 @@ -start at -5: java.lang.IllegalArgumentException: requirement failed: start -5 out of range 10 -start at -1: java.lang.IllegalArgumentException: requirement failed: start -1 out of range 10 -start at limit: java.lang.IllegalArgumentException: requirement failed: start 10 out of range 10 +start at -5: java.lang.ArrayIndexOutOfBoundsException: -5 +start at -1: java.lang.ArrayIndexOutOfBoundsException: -1 +start at limit: ok start at limit-1: ok first 10: ok read all: ok @@ -8,8 +8,8 @@ test huge len: ok 5 from 5: ok 20 from 5: ok test len overflow: ok -start beyond limit: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 +start beyond limit: ok read 0: ok read -1: ok -invalid read 0: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 -invalid read -1: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 +invalid read 0: ok +invalid read -1: ok diff --git a/test/files/run/t6827.scala b/test/files/run/t6827.scala index 8e17af09e2..eb020711bb 100644 --- a/test/files/run/t6827.scala +++ b/test/files/run/t6827.scala @@ -31,4 +31,24 @@ object Test extends App { // okay, see SI-7128 "...".toIterator.copyToArray(new Array[Char](0), 0, 0) + + + // Bonus test from @som-snytt to check for overflow in + // index calculations. + def testOverflow(start: Int, len: Int, expected: List[Char]) { + def copyFromIterator = { + val arr = Array.fill[Char](3)('-') + "abc".toIterator.copyToArray(arr, start, len) + arr.toList + } + def copyFromArray = { + val arr = Array.fill[Char](3)('-') + "abc".toArray.copyToArray(arr, start, len) + arr.toList + } + assert(copyFromIterator == expected) + assert(copyFromArray == expected) + } + testOverflow(1, Int.MaxValue - 1, "-ab".toList) + testOverflow(1, Int.MaxValue, "-ab".toList) } diff --git a/test/files/run/t7521/Test.scala b/test/files/run/t7521/Test.scala new file mode 100644 index 0000000000..e9816ad6cb --- /dev/null +++ b/test/files/run/t7521/Test.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + new Wrapper(new Array[Int](1)) + } +} diff --git a/test/files/run/t7521/Wrapper.scala b/test/files/run/t7521/Wrapper.scala new file mode 100644 index 0000000000..0b923f8924 --- /dev/null +++ b/test/files/run/t7521/Wrapper.scala @@ -0,0 +1 @@ +class Wrapper[Repr](val xs: Repr) extends AnyVal diff --git a/test/files/run/t7521b.check b/test/files/run/t7521b.check new file mode 100644 index 0000000000..4d96df106d --- /dev/null +++ b/test/files/run/t7521b.check @@ -0,0 +1,7 @@ += Java Erased Signatures = +public int C.a(Wrapper) +public int C.b(Wrapper) + += Java Generic Signatures = +public int C.a(Wrapper<int[]>) +public int C.b(Wrapper<java.lang.Object>) diff --git a/test/files/run/t7521b.scala b/test/files/run/t7521b.scala new file mode 100644 index 0000000000..c9e27f28b4 --- /dev/null +++ b/test/files/run/t7521b.scala @@ -0,0 +1,20 @@ +class Wrapper[X](x: X) + +class C { + def a(w: Wrapper[Array[Int]]) = 0 + def b(w: Wrapper[Int]) = 0 +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + c.a(new Wrapper(Array(1, 2))) + c.b(new Wrapper(1)) + + val methods = classOf[C].getDeclaredMethods.sortBy(_.getName) + println("= Java Erased Signatures =") + println(methods.mkString("\n")) + println("\n= Java Generic Signatures =") + println(methods.map(_.toGenericString).mkString("\n")) + } +} diff --git a/test/files/run/t8575.scala b/test/files/run/t8575.scala new file mode 100644 index 0000000000..6e3e57f2be --- /dev/null +++ b/test/files/run/t8575.scala @@ -0,0 +1,33 @@ +class E[F] +class A +class B +class C + +trait TypeMember { + type X + + // This call throws an AbstractMethodError, because it invokes the erasure of + // consume(X): Unit that is consume(Object): Unit. But the corresponding + // bridge method is not generated. + consume(value) + + def value: X + def consume(x: X): Unit +} + +object Test extends TypeMember { + type F = A with B + + // works if replaced by type X = E[A with B with C] + type X = E[F with C] + + val value = new E[F with C] + + // This call passes, since it invokes consume(E): Unit + consume(value) + def consume(x: X) {} + + def main(args: Array[String]) { + + } +} diff --git a/test/files/run/t8575b.scala b/test/files/run/t8575b.scala new file mode 100644 index 0000000000..0d731ccf9f --- /dev/null +++ b/test/files/run/t8575b.scala @@ -0,0 +1,17 @@ +class A +class B +class C + +object Test { + type F = A with B + + def main(args: Array[String]) { + import reflect.runtime.universe._ + val t1 = typeOf[F with C] + val t2 = typeOf[(A with B) with C] + val t3 = typeOf[A with B with C] + assert(t1 =:= t2) + assert(t2 =:= t3) + assert(t3 =:= t1) + } +} diff --git a/test/files/run/t8575c.scala b/test/files/run/t8575c.scala new file mode 100644 index 0000000000..8219952299 --- /dev/null +++ b/test/files/run/t8575c.scala @@ -0,0 +1,23 @@ +class C + +trait TypeMember { + type X + type Y + type Z +} + +object Test extends TypeMember { + type A = X with Y + type B = Z with A + type F = A with B + + def main(args: Array[String]) { + import reflect.runtime.universe._ + val t1 = typeOf[F with C] + val t2 = typeOf[(A with B) with C] + val t3 = typeOf[A with B with C] + assert(t1 =:= t2) + assert(t2 =:= t3) + assert(t3 =:= t1) + } +} diff --git a/test/files/run/t8710.scala b/test/files/run/t8710.scala new file mode 100644 index 0000000000..15aab5b8a4 --- /dev/null +++ b/test/files/run/t8710.scala @@ -0,0 +1,17 @@ +class Bar(val x: Int) extends AnyVal { + def f: String = f(0) + private def f(x: Int): String = "" +} + +class Baz(val x: Int) extends AnyVal { + def f: String = "123" + private def f(x: Int): String = "" +} +object Baz { + def x(b: Baz) = b.f(0) +} + +object Test extends App { + new Bar(23).f + new Baz(23).f +} diff --git a/test/files/run/t8764.check b/test/files/run/t8764.check deleted file mode 100644 index 6260069602..0000000000 --- a/test/files/run/t8764.check +++ /dev/null @@ -1,5 +0,0 @@ -IntOnly: should return an unboxed int -Int: int -IntAndDouble: should just box and return Anyval -Double: class java.lang.Double -Int: class java.lang.Integer diff --git a/test/files/run/t8764.flags b/test/files/run/t8764.flags deleted file mode 100644 index 48fd867160..0000000000 --- a/test/files/run/t8764.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental diff --git a/test/files/run/t8764.scala b/test/files/run/t8764.scala deleted file mode 100644 index decc658f6e..0000000000 --- a/test/files/run/t8764.scala +++ /dev/null @@ -1,16 +0,0 @@ -object Test extends App { -case class IntOnly(i: Int, j: Int) - -println("IntOnly: should return an unboxed int") -val a = IntOnly(1, 2) -val i: Int = a.productElement(0) -println(s"Int: ${a.productElement(0).getClass}") - -case class IntAndDouble(i: Int, d: Double) - -println("IntAndDouble: should just box and return Anyval") -val b = IntAndDouble(1, 2.0) -val j: AnyVal = b.productElement(0) -println(s"Double: ${b.productElement(1).getClass}") -println(s"Int: ${b.productElement(0).getClass}") -} diff --git a/test/files/run/t8944/A_1.scala b/test/files/run/t8944/A_1.scala new file mode 100644 index 0000000000..7ff80327b0 --- /dev/null +++ b/test/files/run/t8944/A_1.scala @@ -0,0 +1 @@ +case class A(private val x: String) diff --git a/test/files/run/t8944/A_2.scala b/test/files/run/t8944/A_2.scala new file mode 100644 index 0000000000..3dcdea1583 --- /dev/null +++ b/test/files/run/t8944/A_2.scala @@ -0,0 +1,6 @@ +case class Other(private val x: String) // consume a fresh name suffix + +// the param accessor will now be called "x$2", +// whereas the previously compiled client expects it to be called +// x$1 +case class A(private val x: String) diff --git a/test/files/run/t8944/Test_1.scala b/test/files/run/t8944/Test_1.scala new file mode 100644 index 0000000000..fe466693cf --- /dev/null +++ b/test/files/run/t8944/Test_1.scala @@ -0,0 +1,3 @@ +object Test extends App { + val A("") = new A("") +} diff --git a/test/files/run/t8944b.scala b/test/files/run/t8944b.scala new file mode 100644 index 0000000000..f469122ce6 --- /dev/null +++ b/test/files/run/t8944b.scala @@ -0,0 +1,9 @@ +case class A(private var foo: Any) { + def m = { def foo = 42 /*will be lamba lifted to `A#foo$1`*/ } +} +object Test { + def main(args: Array[String]): Unit = { + val A("") = new A("") + new A("").m + } +} diff --git a/test/files/run/t8944c.check b/test/files/run/t8944c.check new file mode 100644 index 0000000000..7738f76980 --- /dev/null +++ b/test/files/run/t8944c.check @@ -0,0 +1,5 @@ +private java.lang.Object Foo.ant() +public java.lang.Object Foo.ant$access$0() +private scala.collection.Seq Foo.cat() +public scala.collection.Seq Foo.cat$access$2() +public java.lang.Object Foo.elk() diff --git a/test/files/run/t8944c.scala b/test/files/run/t8944c.scala new file mode 100644 index 0000000000..95c2143851 --- /dev/null +++ b/test/files/run/t8944c.scala @@ -0,0 +1,8 @@ +case class Foo[A](private val ant: Any, elk: Any, private val cat: A*) + +object Test { + def main(args: Array[String]): Unit = { + def pred(name: String) = Set("ant", "elk", "cat").exists(name contains _) + println(classOf[Foo[_]].getDeclaredMethods.filter(m => pred(m.getName)).sortBy(_.getName).mkString("\n")) + } +} diff --git a/test/files/run/t8955.scala b/test/files/run/t8955.scala new file mode 100644 index 0000000000..afa31aa5d7 --- /dev/null +++ b/test/files/run/t8955.scala @@ -0,0 +1,12 @@ +import scala.collection.parallel.immutable.ParSet + +object Test { + def main(args: Array[String]): Unit = { + for (i <- 1 to 2000) test() + } + + def test() { + ParSet[Int]((1 to 10000): _*) foreach (x => ()) // hangs non deterministically + } +} + diff --git a/test/files/run/t9030.scala b/test/files/run/t9030.scala new file mode 100644 index 0000000000..48d24e5b54 --- /dev/null +++ b/test/files/run/t9030.scala @@ -0,0 +1,19 @@ +object Test extends App { + + // For these methods, the compiler emits calls to BoxesRuntime.equalsNumNum/equalsNumChar/equalsNumObject directly + + def numNum(a: java.lang.Number, b: java.lang.Number) = assert(a == b) + def numChar(a: java.lang.Number, b: java.lang.Character) = assert(a == b) + def numObject(a: java.lang.Number, b: java.lang.Object) = assert(a == b) + + // The compiler doesn't use equalsCharObject directly, but still adding an example for completeness + + def charObject(a: java.lang.Character, b: java.lang.Object) = assert(a == b) + + numNum(new Integer(1), new Integer(1)) + numChar(new Integer(97), new Character('a')) + numObject(new Integer(1), new Integer(1)) + numObject(new Integer(97), new Character('a')) + + charObject(new Character('a'), new Integer(97)) +} |