diff options
Diffstat (limited to 'test')
78 files changed, 1057 insertions, 177 deletions
diff --git a/test/files/buildmanager/t2792/t2792.check b/test/files/buildmanager/t2792/t2792.check index 68e14c6386..00a2b83469 100644 --- a/test/files/buildmanager/t2792/t2792.check +++ b/test/files/buildmanager/t2792/t2792.check @@ -9,3 +9,6 @@ compiling Set(A2.scala) A2.scala:2: error: stable identifier required, but A.x found. import A.x.y ^ +A2.scala:3: error: not found: value y + val z = y + ^ diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 86655ad89c..012460147a 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -808,6 +808,126 @@ trait TryEitherExtractor extends TestBase { testLeftMatch() } +trait CustomExecutionContext extends TestBase { + import scala.concurrent.{ ExecutionContext, Awaitable } + + def defaultEC = ExecutionContext.defaultExecutionContext + + val inEC = new java.lang.ThreadLocal[Int]() { + override def initialValue = 0 + } + + def enterEC() = inEC.set(inEC.get + 1) + def leaveEC() = inEC.set(inEC.get - 1) + def assertEC() = assert(inEC.get > 0) + def assertNoEC() = assert(inEC.get == 0) + + class CountingExecutionContext extends ExecutionContext { + val _count = new java.util.concurrent.atomic.AtomicInteger(0) + def count = _count.get + + def delegate = ExecutionContext.defaultExecutionContext + + override def execute(runnable: Runnable) = { + _count.incrementAndGet() + val wrapper = new Runnable() { + override def run() = { + enterEC() + try { + runnable.run() + } finally { + leaveEC() + } + } + } + delegate.execute(wrapper) + } + + override def internalBlockingCall[T](awaitable: Awaitable[T], atMost: Duration): T = + delegate.internalBlockingCall(awaitable, atMost) + + override def reportFailure(t: Throwable): Unit = { + System.err.println("Failure: " + t.getClass.getSimpleName + ": " + t.getMessage) + delegate.reportFailure(t) + } + } + + def countExecs(block: (ExecutionContext) => Unit): Int = { + val context = new CountingExecutionContext() + block(context) + context.count + } + + def testOnSuccessCustomEC(): Unit = { + val count = countExecs { implicit ec => + once { done => + val f = future({ assertNoEC() })(defaultEC) + f onSuccess { + case _ => + assertEC() + done() + } + assertNoEC() + } + } + + // should be onSuccess, but not future body + assert(count == 1) + } + + def testKeptPromiseCustomEC(): Unit = { + val count = countExecs { implicit ec => + once { done => + val f = Promise.successful(10).future + f onSuccess { + case _ => + assertEC() + done() + } + } + } + + // should be onSuccess called once in proper EC + assert(count == 1) + } + + def testCallbackChainCustomEC(): Unit = { + val count = countExecs { implicit ec => + once { done => + assertNoEC() + val addOne = { x: Int => assertEC(); x + 1 } + val f = Promise.successful(10).future + f.map(addOne).filter { x => + assertEC() + x == 11 + } flatMap { x => + Promise.successful(x + 1).future.map(addOne).map(addOne) + } onComplete { + case Left(t) => + try { + throw new AssertionError("error in test: " + t.getMessage, t) + } finally { + done() + } + case Right(x) => + assertEC() + assert(x == 14) + done() + } + assertNoEC() + } + } + + // the count is not defined (other than >=1) + // due to the batching optimizations. + assert(count >= 1) + } + + testOnSuccessCustomEC() + testKeptPromiseCustomEC() + testCallbackChainCustomEC() +} + object Test extends App with FutureCallbacks @@ -816,6 +936,7 @@ with FutureProjections with Promises with Exceptions with TryEitherExtractor +with CustomExecutionContext { System.exit(0) } diff --git a/test/files/neg/exhausting.check b/test/files/neg/exhausting.check index 0bef21e077..7140b99428 100644 --- a/test/files/neg/exhausting.check +++ b/test/files/neg/exhausting.check @@ -1,29 +1,25 @@ -exhausting.scala:20: error: match is not exhaustive! -missing combination * Nil - +exhausting.scala:21: error: match may not be exhaustive. +It would fail on the following input: List(_, _, _) def fail1[T](xs: List[T]) = xs match { ^ -exhausting.scala:24: error: match is not exhaustive! -missing combination Nil - +exhausting.scala:27: error: match may not be exhaustive. +It would fail on the following input: Nil def fail2[T](xs: List[T]) = xs match { ^ -exhausting.scala:27: error: match is not exhaustive! -missing combination Bar3 - +exhausting.scala:32: error: match may not be exhaustive. +It would fail on the following input: List(<not in (1, 2)>) + def fail3a(xs: List[Int]) = xs match { + ^ +exhausting.scala:39: error: match may not be exhaustive. +It would fail on the following input: Bar3 def fail3[T](x: Foo[T]) = x match { ^ -exhausting.scala:31: error: match is not exhaustive! -missing combination Bar2 Bar2 - +exhausting.scala:47: error: match may not be exhaustive. +It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2) def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { ^ -exhausting.scala:36: error: match is not exhaustive! -missing combination Bar1 Bar2 -missing combination Bar1 Bar3 -missing combination Bar2 Bar1 -missing combination Bar2 Bar2 - +exhausting.scala:56: error: match may not be exhaustive. +It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2) def fail5[T](xx: (Foo[T], Foo[T])) = xx match { ^ -5 errors found +6 errors found diff --git a/test/files/neg/exhausting.flags b/test/files/neg/exhausting.flags index b7eb21d5f5..85d8eb2ba2 100644 --- a/test/files/neg/exhausting.flags +++ b/test/files/neg/exhausting.flags @@ -1 +1 @@ --Xfatal-warnings -Xoldpatmat +-Xfatal-warnings diff --git a/test/files/neg/exhausting.scala b/test/files/neg/exhausting.scala index 14b05695aa..5554ee2671 100644 --- a/test/files/neg/exhausting.scala +++ b/test/files/neg/exhausting.scala @@ -16,30 +16,46 @@ object Test { def ex3[T](xx: (Foo[T], Foo[T])) = xx match { case (_: Foo[_], _: Foo[_]) => () } - + + // fails for: ::(_, ::(_, ::(_, _))) def fail1[T](xs: List[T]) = xs match { case Nil => "ok" case x :: y :: Nil => "ok" } + + // fails for: Nil def fail2[T](xs: List[T]) = xs match { case _ :: _ => "ok" } + + // fails for: ::(<not in (2, 1)>, _) + def fail3a(xs: List[Int]) = xs match { + case 1 :: _ => + case 2 :: _ => + case Nil => + } + + // fails for: Bar3 def fail3[T](x: Foo[T]) = x match { case Bar1 => "ok" case Bar2 => "ok" } + // fails for: (Bar1, Bar2) + // fails for: (Bar1, Bar3) + // fails for: (Bar2, Bar2) + // fails for: (Bar2, Bar1) def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { case (Bar1, Bar1) => () case (Bar2, Bar3) => () case (Bar3, _) => () } + // fails for: (Bar1, Bar2) + // fails for: (Bar1, Bar3) + // fails for: (Bar2, Bar1) + // fails for: (Bar2, Bar2) def fail5[T](xx: (Foo[T], Foo[T])) = xx match { case (Bar1, Bar1) => () case (Bar2, Bar3) => () case (Bar3, _) => () } - - def main(args: Array[String]): Unit = { - - } } diff --git a/test/files/neg/pat_unreachable.flags b/test/files/neg/pat_unreachable.flags index ba80cad69b..cb8324a345 100644 --- a/test/files/neg/pat_unreachable.flags +++ b/test/files/neg/pat_unreachable.flags @@ -1 +1 @@ --Xoldpatmat +-Xoldpatmat
\ No newline at end of file diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 5426d61d31..6172811e13 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -1,54 +1,41 @@ -patmatexhaust.scala:7: error: match is not exhaustive! -missing combination Baz - +patmatexhaust.scala:7: error: match may not be exhaustive. +It would fail on the following input: Baz def ma1(x:Foo) = x match { ^ -patmatexhaust.scala:11: error: match is not exhaustive! -missing combination Bar - +patmatexhaust.scala:11: error: match may not be exhaustive. +It would fail on the following input: Bar(_) def ma2(x:Foo) = x match { ^ -patmatexhaust.scala:23: error: match is not exhaustive! -missing combination Kult Kult -missing combination Qult Qult - +patmatexhaust.scala:23: error: match may not be exhaustive. +It would fail on the following inputs: (Kult(_), Kult(_)), (Qult(), Qult()) def ma3(x:Mult) = (x,x) match { // not exhaustive ^ -patmatexhaust.scala:49: error: match is not exhaustive! -missing combination Gp -missing combination Gu - +patmatexhaust.scala:49: error: match may not be exhaustive. +It would fail on the following inputs: Gp(), Gu def ma4(x:Deep) = x match { // missing cases: Gu, Gp ^ -patmatexhaust.scala:53: error: match is not exhaustive! -missing combination Gp - - def ma5(x:Deep) = x match { // Gp +patmatexhaust.scala:53: error: match may not be exhaustive. +It would fail on the following input: Gp() + def ma5(x:Deep) = x match { ^ -patmatexhaust.scala:59: error: match is not exhaustive! -missing combination Nil - +patmatexhaust.scala:59: error: match may not be exhaustive. +It would fail on the following input: Nil def ma6() = List(1,2) match { // give up ^ -patmatexhaust.scala:75: error: match is not exhaustive! -missing combination B - +patmatexhaust.scala:75: error: match may not be exhaustive. +It would fail on the following input: B() def ma9(x: B) = x match { ^ -patmatexhaust.scala:100: error: match is not exhaustive! -missing combination C1 - +patmatexhaust.scala:100: error: match may not be exhaustive. +It would fail on the following input: C1() def ma10(x: C) = x match { // not exhaustive: C1 is not sealed. ^ -patmatexhaust.scala:114: error: match is not exhaustive! -missing combination D1 -missing combination D2 - +patmatexhaust.scala:114: error: match may not be exhaustive. +It would fail on the following inputs: D1, D2() def ma10(x: C) = x match { // not exhaustive: C1 has subclasses. ^ -patmatexhaust.scala:126: error: match is not exhaustive! -missing combination C1 - +patmatexhaust.scala:126: error: match may not be exhaustive. +It would fail on the following input: C1() def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. ^ 10 errors found diff --git a/test/files/neg/patmatexhaust.flags b/test/files/neg/patmatexhaust.flags index b7eb21d5f5..85d8eb2ba2 100644 --- a/test/files/neg/patmatexhaust.flags +++ b/test/files/neg/patmatexhaust.flags @@ -1 +1 @@ --Xfatal-warnings -Xoldpatmat +-Xfatal-warnings diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala index 9297e09d0d..ceb960ee97 100644 --- a/test/files/neg/patmatexhaust.scala +++ b/test/files/neg/patmatexhaust.scala @@ -50,7 +50,7 @@ class TestSealedExhaustive { // compile only case Ga => } - def ma5(x:Deep) = x match { // Gp + def ma5(x:Deep) = x match { case Gu => case _ if 1 == 0 => case Ga => diff --git a/test/files/neg/sealed-java-enums.check b/test/files/neg/sealed-java-enums.check index 9303c2df9c..20d00c8e91 100644 --- a/test/files/neg/sealed-java-enums.check +++ b/test/files/neg/sealed-java-enums.check @@ -1,9 +1,5 @@ -sealed-java-enums.scala:5: error: match is not exhaustive! -missing combination BLOCKED -missing combination State -missing combination TERMINATED -missing combination TIMED_WAITING - +sealed-java-enums.scala:5: error: match may not be exhaustive. +It would fail on the following inputs: BLOCKED, TERMINATED, TIMED_WAITING def f(state: State) = state match { ^ one error found diff --git a/test/files/neg/sealed-java-enums.flags b/test/files/neg/sealed-java-enums.flags index 312f3a87ec..e709c65918 100644 --- a/test/files/neg/sealed-java-enums.flags +++ b/test/files/neg/sealed-java-enums.flags @@ -1 +1 @@ --Xexperimental -Xfatal-warnings -Xoldpatmat +-Xexperimental -Xfatal-warnings diff --git a/test/files/neg/switch.check b/test/files/neg/switch.check index 7212c1a22b..8955c94b32 100644 --- a/test/files/neg/switch.check +++ b/test/files/neg/switch.check @@ -1,10 +1,10 @@ switch.scala:28: error: could not emit switch for @switch annotated match def fail1(c: Char) = (c: @switch) match { - ^ + ^ switch.scala:38: error: could not emit switch for @switch annotated match def fail2(c: Char) = (c: @switch @unchecked) match { - ^ + ^ switch.scala:45: error: could not emit switch for @switch annotated match def fail3(c: Char) = (c: @unchecked @switch) match { - ^ + ^ three errors found diff --git a/test/files/neg/switch.flags b/test/files/neg/switch.flags index 809e9ff2f2..e8fb65d50c 100644 --- a/test/files/neg/switch.flags +++ b/test/files/neg/switch.flags @@ -1 +1 @@ - -Xoldpatmat +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t2405.check b/test/files/neg/t2405.check new file mode 100644 index 0000000000..78360bcc21 --- /dev/null +++ b/test/files/neg/t2405.check @@ -0,0 +1,8 @@ +t2405.scala:6: warning: imported `y' is permanently hidden by definition of method y + import A.{x => y} + ^ +t2405.scala:8: error: could not find implicit value for parameter e: Int + implicitly[Int] + ^ +one warning found +one error found diff --git a/test/files/neg/t2405.scala b/test/files/neg/t2405.scala new file mode 100644 index 0000000000..6982285b98 --- /dev/null +++ b/test/files/neg/t2405.scala @@ -0,0 +1,10 @@ +object A { implicit val x: Int = 1 } + +// Expecting shadowing #1 +object Test2 { + { + import A.{x => y} + def y: Int = 0 + implicitly[Int] + } +} diff --git a/test/files/neg/t3098.check b/test/files/neg/t3098.check index 403da281c8..85829747b9 100644 --- a/test/files/neg/t3098.check +++ b/test/files/neg/t3098.check @@ -1,6 +1,5 @@ -b.scala:3: error: match is not exhaustive! -missing combination C - +b.scala:3: error: match may not be exhaustive. +It would fail on the following input: (_ : C) def f = (null: T) match { ^ one error found diff --git a/test/files/neg/t3098.flags b/test/files/neg/t3098.flags index b7eb21d5f5..85d8eb2ba2 100644 --- a/test/files/neg/t3098.flags +++ b/test/files/neg/t3098.flags @@ -1 +1 @@ --Xfatal-warnings -Xoldpatmat +-Xfatal-warnings diff --git a/test/files/neg/t3614.check b/test/files/neg/t3614.check new file mode 100644 index 0000000000..5fdb5cbf1f --- /dev/null +++ b/test/files/neg/t3614.check @@ -0,0 +1,4 @@ +t3614.scala:2: error: class type required but AnyRef{def a: <?>} found + def v = new ({ def a=0 }) + ^ +one error found
\ No newline at end of file diff --git a/test/files/neg/t3614.scala b/test/files/neg/t3614.scala new file mode 100644 index 0000000000..5b02cdf2b2 --- /dev/null +++ b/test/files/neg/t3614.scala @@ -0,0 +1,3 @@ +object t3614 { + def v = new ({ def a=0 }) +}
\ No newline at end of file diff --git a/test/files/neg/t3683a.check b/test/files/neg/t3683a.check index 18e80dd5e8..3de3ad784e 100644 --- a/test/files/neg/t3683a.check +++ b/test/files/neg/t3683a.check @@ -1,6 +1,5 @@ -t3683a.scala:14: error: match is not exhaustive! -missing combination XX - +t3683a.scala:14: error: match may not be exhaustive. +It would fail on the following input: XX() w match { ^ one error found diff --git a/test/files/neg/t3683a.flags b/test/files/neg/t3683a.flags index b7eb21d5f5..85d8eb2ba2 100644 --- a/test/files/neg/t3683a.flags +++ b/test/files/neg/t3683a.flags @@ -1 +1 @@ --Xfatal-warnings -Xoldpatmat +-Xfatal-warnings diff --git a/test/files/neg/t3692-new.flags b/test/files/neg/t3692-new.flags index 82becdfbfd..cb8324a345 100644 --- a/test/files/neg/t3692-new.flags +++ b/test/files/neg/t3692-new.flags @@ -1 +1 @@ - -Xoldpatmat
\ No newline at end of file +-Xoldpatmat
\ No newline at end of file diff --git a/test/files/neg/t3692-old.flags b/test/files/neg/t3692-old.flags index 82becdfbfd..cb8324a345 100644 --- a/test/files/neg/t3692-old.flags +++ b/test/files/neg/t3692-old.flags @@ -1 +1 @@ - -Xoldpatmat
\ No newline at end of file +-Xoldpatmat
\ No newline at end of file diff --git a/test/files/neg/t3761-overload-byname.check b/test/files/neg/t3761-overload-byname.check new file mode 100644 index 0000000000..ae7d21dfa6 --- /dev/null +++ b/test/files/neg/t3761-overload-byname.check @@ -0,0 +1,13 @@ +t3761-overload-byname.scala:9: error: ambiguous reference to overloaded definition, +both method m1 in object t of type (x: => Int, s: Object)Int +and method m1 in object t of type (x: => AnyVal, s: String)Int +match argument types (Int,String) + m1(1, "") + ^ +t3761-overload-byname.scala:11: error: ambiguous reference to overloaded definition, +both method m2 in object t of type (x: => Int, s: Object)Int +and method m2 in object t of type (x: => Any, s: String)Int +match argument types (Int,String) + m2(1, "") + ^ +two errors found diff --git a/test/files/neg/t3761-overload-byname.scala b/test/files/neg/t3761-overload-byname.scala new file mode 100644 index 0000000000..5b9a381b93 --- /dev/null +++ b/test/files/neg/t3761-overload-byname.scala @@ -0,0 +1,13 @@ +object t { + def m1(x: => AnyVal, s: String) = 0 + def m1(x: => Int, s: Object) = 1 + + def m2(x: => Any, s: String) = 0 + def m2(x: => Int, s: Object) = 1 + + + m1(1, "") + m1(1d, "") + m2(1, "") + m2("", "") +} diff --git a/test/files/neg/t5735.check b/test/files/neg/t5735.check new file mode 100644 index 0000000000..f6e0028044 --- /dev/null +++ b/test/files/neg/t5735.check @@ -0,0 +1,6 @@ +t5735.scala:6: error: type mismatch; + found : (x: Int)Int <and> => String + required: Int + val z: Int = a + ^ +one error found diff --git a/test/files/neg/t5735.scala b/test/files/neg/t5735.scala new file mode 100644 index 0000000000..fde71ff962 --- /dev/null +++ b/test/files/neg/t5735.scala @@ -0,0 +1,7 @@ +abstract class Base { + def a: String = "one" +} +class Clazz extends Base { + def a(x: Int): Int = 2 + val z: Int = a +} diff --git a/test/files/neg/t5760-pkgobj-warn.check b/test/files/neg/t5760-pkgobj-warn.check new file mode 100644 index 0000000000..a89398c3f7 --- /dev/null +++ b/test/files/neg/t5760-pkgobj-warn.check @@ -0,0 +1,4 @@ +stalepkg_2.scala:6: error: Foo is already defined as class Foo in package object stalepkg + class Foo + ^ +one error found diff --git a/test/files/neg/t5760-pkgobj-warn/stalepkg_1.scala b/test/files/neg/t5760-pkgobj-warn/stalepkg_1.scala new file mode 100644 index 0000000000..ed4b731bb0 --- /dev/null +++ b/test/files/neg/t5760-pkgobj-warn/stalepkg_1.scala @@ -0,0 +1,11 @@ + +package object stalepkg { + class Foo +} + +package stalepkg { + object Test { + def main(args: Array[String]) { + } + } +} diff --git a/test/files/neg/t5760-pkgobj-warn/stalepkg_2.scala b/test/files/neg/t5760-pkgobj-warn/stalepkg_2.scala new file mode 100644 index 0000000000..9abcdbab17 --- /dev/null +++ b/test/files/neg/t5760-pkgobj-warn/stalepkg_2.scala @@ -0,0 +1,11 @@ + +package object stalepkg { +} + +package stalepkg { + class Foo + object Test { + def main(args: Array[String]) { + } + } +} diff --git a/test/files/neg/t5821.check b/test/files/neg/t5821.check new file mode 100644 index 0000000000..f9c00604bc --- /dev/null +++ b/test/files/neg/t5821.check @@ -0,0 +1,4 @@ +t5821.scala:1: error: not found: object SthImportant +import SthImportant._ + ^ +one error found diff --git a/test/files/neg/t5821.scala b/test/files/neg/t5821.scala new file mode 100644 index 0000000000..4af0a2bf7f --- /dev/null +++ b/test/files/neg/t5821.scala @@ -0,0 +1,8 @@ +import SthImportant._ + +class Bar + +class Foo2 { + type Sth = Array[Bar] + def foo(xs: Sth): Bar = if ((xs eq null) || (xs.length == 0)) null else xs(0) +} diff --git a/test/files/neg/t639.check b/test/files/neg/t639.check index 3b53da0515..6d41d872de 100644 --- a/test/files/neg/t639.check +++ b/test/files/neg/t639.check @@ -1,4 +1,7 @@ t639.scala:3: error: not found: object a import a._ ^ -one error found +t639.scala:5: error: not found: type B +@B + ^ +two errors found diff --git a/test/files/neg/t963b.check b/test/files/neg/t963b.check new file mode 100644 index 0000000000..9918a98c46 --- /dev/null +++ b/test/files/neg/t963b.check @@ -0,0 +1,6 @@ +t963b.scala:25: error: type mismatch; + found : B.type + required: AnyRef{val y: A} + B.f(B) + ^ +one error found diff --git a/test/pending/neg/t963.scala b/test/files/neg/t963b.scala index 3be0be1b84..b34aae8095 100644 --- a/test/pending/neg/t963.scala +++ b/test/files/neg/t963b.scala @@ -5,8 +5,8 @@ trait A { } object B { - def f(x : { val y : A }) { x.y.v = x.y.v } - + def f(x : { val y : A }) { x.y.v = x.y.v } + var a : A = _ var b : Boolean = false def y : A = { @@ -21,6 +21,6 @@ object B { } } -object Test extends Application { +object Test extends App { B.f(B) } diff --git a/test/files/pos/arrays3.scala b/test/files/pos/arrays3.scala new file mode 100644 index 0000000000..f96be0b427 --- /dev/null +++ b/test/files/pos/arrays3.scala @@ -0,0 +1,11 @@ +trait Foo { + type Repr <: String + def f2(x: Repr) = x.length +} +trait Fooz[Repr <: Array[_]] { + def f0(x: Repr) = x.length +} + +trait Bar[Repr <: List[_]] extends Foo with Fooz[Array[Int]] { + def f1(x: Repr) = x.length +} diff --git a/test/files/pos/exhaust_alternatives.flags b/test/files/pos/exhaust_alternatives.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/pos/exhaust_alternatives.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/exhaust_alternatives.scala b/test/files/pos/exhaust_alternatives.scala new file mode 100644 index 0000000000..cc81d0be7d --- /dev/null +++ b/test/files/pos/exhaust_alternatives.scala @@ -0,0 +1,10 @@ +sealed abstract class X +sealed case class A(x: Boolean) extends X +case object B extends X + +object Test { + def test(x: X) = x match { + case A(true) => + case A(false) | B => + } +}
\ No newline at end of file diff --git a/test/files/pos/exhaustive_heuristics.scala b/test/files/pos/exhaustive_heuristics.scala new file mode 100644 index 0000000000..f6bea455a5 --- /dev/null +++ b/test/files/pos/exhaustive_heuristics.scala @@ -0,0 +1,16 @@ +// tests exhaustivity doesn't give warnings (due to its heuristic rewrites kicking in or it backing off) +object Test { + // List() => Nil + List(1) match { + case List() => + case x :: xs => + } + + // we don't look into guards + val turnOffChecks = true + List(1) match { + case _ if turnOffChecks => + } + + // TODO: we back off when there are any user-defined extractors +}
\ No newline at end of file diff --git a/test/files/pos/t2405.scala b/test/files/pos/t2405.scala new file mode 100644 index 0000000000..224b2ce83b --- /dev/null +++ b/test/files/pos/t2405.scala @@ -0,0 +1,23 @@ +object A { implicit val x: Int = 1 } + +// Problem as stated in the ticket. +object Test1 { + import A.{x => y} + implicitly[Int] +} + +// Testing for the absense of shadowing #1. +object Test2 { + import A.{x => y} + val x = 2 + implicitly[Int] +} + +// Testing for the absense of shadowing #2. +object Test3 { + { + import A.{x => y} + def x: Int = 0 + implicitly[Int] + } +} diff --git a/test/files/pos/t3097.scala b/test/files/pos/t3097.scala deleted file mode 100644 index a034b960f7..0000000000 --- a/test/files/pos/t3097.scala +++ /dev/null @@ -1,31 +0,0 @@ -package seal - -sealed trait ISimpleValue - -sealed trait IListValue extends ISimpleValue { - def items: List[IAtomicValue[_]] -} -sealed trait IAtomicValue[O] extends ISimpleValue { - def data: O -} - -sealed trait IAbstractDoubleValue[O] extends IAtomicValue[O] { } -sealed trait IDoubleValue extends IAbstractDoubleValue[Double] - -case class ListValue(val items: List[IAtomicValue[_]]) extends IListValue -class DoubleValue(val data: Double) extends IDoubleValue { - def asDouble = data -} - -object Test { - /** - * @param args the command line arguments - */ - def main(args: Array[String]): Unit = { - val v: ISimpleValue = new DoubleValue(1) - v match { - case m: IListValue => println("list") - case a: IAtomicValue[_] => println("atomic") - } - } -} diff --git a/test/files/pos/t3856.scala b/test/files/pos/t3856.scala index fd253a56a8..5ea4b84e2c 100644 --- a/test/files/pos/t3856.scala +++ b/test/files/pos/t3856.scala @@ -2,6 +2,7 @@ case class C[T](x: T) case class CS(xs: C[_]*) +// t3856 object Test { val x = CS(C(5), C("abc")) match { case CS(C(5), xs @ _*) => xs } println(x) diff --git a/test/files/pos/t3880.scala b/test/files/pos/t3880.scala new file mode 100644 index 0000000000..b6f06c43a3 --- /dev/null +++ b/test/files/pos/t3880.scala @@ -0,0 +1,16 @@ +abstract class Bar[+B] { +} +abstract class C1[+B] extends Bar[B] { + private[this] def g(x: C1[B]): Unit = () + + // this method is fine: notice that it allows the call to g, + // which requires C1[B], even though we matched on C1[_]. + // (That is good news.) + private[this] def f1(x: Bar[B]): Unit = x match { + case x: C1[_] => g(x) + } + // this one crashes. + private[this] def f2(x: Bar[B]): Unit = x match { + case x: C1[_] => f2(x) + } +}
\ No newline at end of file diff --git a/test/files/pos/t4717.scala b/test/files/pos/t4717.scala new file mode 100644 index 0000000000..4acfe489cc --- /dev/null +++ b/test/files/pos/t4717.scala @@ -0,0 +1,35 @@ + + + + + + + +trait Bug1[@specialized(Boolean) A] extends TraversableOnce[A] { + + def ++[B >: A](that: TraversableOnce[B]): Iterator[B] = new Iterator[B] { + lazy val it = that.toIterator + def hasNext = it.hasNext + def next = it.next + } + +} + + + +trait WorksFine[@specialized(Boolean) A] { + class SubBounds[B >: A] extends Bounds[B] { + lazy val it = ??? + } + def x[B >: A]: Unit = new SubBounds[B] +} + + +trait Bounds[@specialized(Boolean) A] { + // okay without `>: A` + def x[B >: A]: Unit = new Bounds[B] { + lazy val it = ??? // def or val okay + } +} + + diff --git a/test/files/pos/t4975.scala b/test/files/pos/t4975.scala new file mode 100644 index 0000000000..12d889c0d5 --- /dev/null +++ b/test/files/pos/t4975.scala @@ -0,0 +1,12 @@ +object ImplicitScope { + class A[T] + + def foo { + trait B + object B { + implicit def ab = new A[B] + } + + implicitly[A[B]] // Error + } +} diff --git a/test/files/pos/t5305.scala b/test/files/pos/t5305.scala new file mode 100644 index 0000000000..4c32cd7c6d --- /dev/null +++ b/test/files/pos/t5305.scala @@ -0,0 +1,13 @@ +object t5305 { + def in(a: Any) = {} + + object O { + type F = Int + val v = "" + } + + in { + import O.{F, v} + type x = {type l = (F, v.type)} // not found: type F + } +} diff --git a/test/files/pos/t5779-numeq-warn.scala b/test/files/pos/t5779-numeq-warn.scala new file mode 100644 index 0000000000..76ef2970fd --- /dev/null +++ b/test/files/pos/t5779-numeq-warn.scala @@ -0,0 +1,13 @@ + +object Test { + def main(args: Array[String]) { + val d: Double = (BigInt(1) << 64).toDouble + val f: Float = d.toFloat + val n: java.lang.Number = d.toFloat + assert (d == f) // ok + assert (d == n) // was: comparing values of types Double and Number using `==' will always yield false + assert (n == d) // was: Number and Double are unrelated: they will most likely never compare equal + assert (f == n) + assert (n == f) + } +} diff --git a/test/files/pos/t5809.flags b/test/files/pos/t5809.flags new file mode 100644 index 0000000000..e93641e931 --- /dev/null +++ b/test/files/pos/t5809.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/t5809.scala b/test/files/pos/t5809.scala new file mode 100644 index 0000000000..8f6ce708d2 --- /dev/null +++ b/test/files/pos/t5809.scala @@ -0,0 +1,10 @@ +package scala.reflect + +package object api { + implicit class PimpedExpr[T](expr: Universe # Expr[T]) { + def runtimeEval: T = { + println("hello, dear") + expr.eval + } + } +}
\ No newline at end of file diff --git a/test/files/pos/virtpatmat_exhaust.scala b/test/files/pos/virtpatmat_exhaust.scala new file mode 100644 index 0000000000..a2f47c88c8 --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = opt match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} diff --git a/test/files/pos/virtpatmat_exhaust_unchecked.flags b/test/files/pos/virtpatmat_exhaust_unchecked.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust_unchecked.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/pos/virtpatmat_exhaust_unchecked.scala b/test/files/pos/virtpatmat_exhaust_unchecked.scala new file mode 100644 index 0000000000..641f2b4f9a --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust_unchecked.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = (opt: @unchecked) match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + // case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} diff --git a/test/files/pos/z1730.flags b/test/files/pos/z1730.flags new file mode 100644 index 0000000000..5319681590 --- /dev/null +++ b/test/files/pos/z1730.flags @@ -0,0 +1 @@ +-Ycheck:all
\ No newline at end of file diff --git a/test/files/pos/z1730.scala b/test/files/pos/z1730.scala new file mode 100644 index 0000000000..0c5875a818 --- /dev/null +++ b/test/files/pos/z1730.scala @@ -0,0 +1,13 @@ +// /scala/trac/z1730/a.scala +// Wed May 23 07:41:25 PDT 2012 + +class X[R] { + def xx(value: => R, addTweak: Boolean = true) = 0 +} + +class Boo { + implicit def toX[R](v: R) : X[R] = null + def goo2 { + 3.xx(34) + } +} diff --git a/test/files/run/inline-ex-handlers.check b/test/files/run/inline-ex-handlers.check index a5d7e93334..708fcc6985 100644 --- a/test/files/run/inline-ex-handlers.check +++ b/test/files/run/inline-ex-handlers.check @@ -1,27 +1,23 @@ 172c172 -< locals: value x$1, value x1, value x2, value x +< locals: value x$1, value x1 --- -> locals: value x$1, value x1, value x2, value x, variable boxed1 +> locals: value x$1, value x1, variable boxed1 174c174 -< blocks: [1,2,3,5,6,7] +< blocks: [1,2,3,4] --- -> blocks: [1,3,5,6] -180,182d179 +> blocks: [1,3,4] +186a187,188 +> 92 STORE_LOCAL(variable boxed1) +> 92 LOAD_LOCAL(variable boxed1) +195,197d196 < 92 JUMP 2 < < 2: -194,196d190 -< 92 JUMP 7 -< -< 7: -204a199,200 -> 92 STORE_LOCAL(variable boxed1) -> 92 LOAD_LOCAL(variable boxed1) -395c391 +385c384 < blocks: [1,2,3,4,5,8,11,13,14,16] --- > blocks: [1,2,3,5,8,11,13,14,16,17] -419c415,424 +409c408,417 < 103 THROW(MyException) --- > ? STORE_LOCAL(value ex5) @@ -34,15 +30,15 @@ > 106 LOAD_LOCAL(value x3) > 106 IS_INSTANCE REF(class MyException) > 106 CZJUMP (BOOL)NE ? 5 : 11 -432,434d436 +422,424d429 < 101 JUMP 4 < < 4: -522c524 +512c517 < blocks: [1,2,3,4,6,7,8,9,10] --- > blocks: [1,2,3,4,6,7,8,9,10,11,12,13] -551c553,558 +541c546,551 < 306 THROW(MyException) --- > ? JUMP 11 @@ -51,7 +47,7 @@ > ? LOAD_LOCAL(variable monitor4) > 305 MONITOR_EXIT > ? JUMP 12 -557c564,570 +547c557,563 < ? THROW(Throwable) --- > ? JUMP 12 @@ -61,7 +57,7 @@ > 304 MONITOR_EXIT > ? STORE_LOCAL(value t) > ? JUMP 13 -563c576,589 +553c569,582 < ? THROW(Throwable) --- > ? STORE_LOCAL(value t) @@ -78,30 +74,29 @@ > 310 CALL_PRIMITIVE(EndConcat) > 310 CALL_METHOD scala.Predef.println (dynamic) > 310 JUMP 2 -587c613 +577c606 < catch (Throwable) in ArrayBuffer(7, 8, 9, 10) starting at: 6 --- > catch (Throwable) in ArrayBuffer(7, 8, 9, 10, 11) starting at: 6 -590c616 +580c609 < catch (Throwable) in ArrayBuffer(4, 6, 7, 8, 9, 10) starting at: 3 --- > catch (Throwable) in ArrayBuffer(4, 6, 7, 8, 9, 10, 11, 12) starting at: 3 -622c648 +612c641 < blocks: [1,2,3,4,5,6,7,9,10] --- > blocks: [1,2,3,4,5,6,7,9,10,11,12] -646c672,673 +636c665,671 < 78 THROW(IllegalArgumentException) --- > ? STORE_LOCAL(value e) > ? JUMP 11 -647a675,679 +> > 11: > 81 LOAD_LOCAL(value e) > ? STORE_LOCAL(variable exc1) > ? JUMP 12 -> -675c707,721 +665c700,714 < 81 THROW(Exception) --- > ? STORE_LOCAL(variable exc1) @@ -119,15 +114,15 @@ > 84 STORE_LOCAL(variable result) > 84 LOAD_LOCAL(variable exc1) > 84 THROW(Throwable) -697c743 +687c736 < catch (<none>) in ArrayBuffer(4, 6, 7, 9) starting at: 3 --- > catch (<none>) in ArrayBuffer(4, 6, 7, 9, 11) starting at: 3 -723c769 +713c762 < blocks: [1,2,3,4,5,6,9,12,14,17,18,19,22,25,27,28,30,31] --- > blocks: [1,2,3,4,5,6,9,12,14,17,18,19,22,25,27,28,30,31,32,33,34] -747c793,800 +737c786,793 < 172 THROW(MyException) --- > ? STORE_LOCAL(value ex5) @@ -138,12 +133,12 @@ > 170 STORE_LOCAL(value x3) > 170 SCOPE_ENTER value x3 > 170 JUMP 18 -803c856,857 +793c849,850 < 177 THROW(MyException) --- > ? STORE_LOCAL(value ex5) > ? JUMP 33 -807c861,868 +797c854,861 < 170 THROW(Throwable) --- > ? STORE_LOCAL(value ex5) @@ -154,17 +149,17 @@ > 169 STORE_LOCAL(value x3) > 169 SCOPE_ENTER value x3 > 169 JUMP 5 -840c901,902 +830c894,895 < 182 THROW(MyException) --- > ? STORE_LOCAL(variable exc2) > ? JUMP 34 -844c906,907 +834c899,900 < 169 THROW(Throwable) --- > ? STORE_LOCAL(variable exc2) > ? JUMP 34 -845a909,921 +835a902,914 > 34: > 184 LOAD_MODULE object Predef > 184 CONSTANT("finally") @@ -178,19 +173,19 @@ > 185 LOAD_LOCAL(variable exc2) > 185 THROW(Throwable) > -866c942 +856c935 < catch (Throwable) in ArrayBuffer(17, 18, 19, 22, 25, 27, 28, 30) starting at: 4 --- > catch (Throwable) in ArrayBuffer(17, 18, 19, 22, 25, 27, 28, 30, 32) starting at: 4 -869c945 +859c938 < catch (<none>) in ArrayBuffer(4, 5, 6, 9, 12, 17, 18, 19, 22, 25, 27, 28, 30) starting at: 3 --- > catch (<none>) in ArrayBuffer(4, 5, 6, 9, 12, 17, 18, 19, 22, 25, 27, 28, 30, 32, 33) starting at: 3 -895c971 +885c964 < blocks: [1,2,3,6,7,8,11,14,16,17,19] --- > blocks: [1,2,3,6,7,8,11,14,16,17,19,20] -919c995,1002 +909c988,995 < 124 THROW(MyException) --- > ? STORE_LOCAL(value ex5) @@ -201,15 +196,15 @@ > 122 STORE_LOCAL(value x3) > 122 SCOPE_ENTER value x3 > 122 JUMP 7 -979c1062 +969c1055 < catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 14, 16, 17, 19) starting at: 3 --- > catch (IllegalArgumentException) in ArrayBuffer(6, 7, 8, 11, 14, 16, 17, 19, 20) starting at: 3 -1005c1088 +995c1081 < blocks: [1,2,3,4,5,8,11,15,16,17,19] --- > blocks: [1,2,3,5,8,11,15,16,17,19,20] -1029c1112,1121 +1019c1105,1114 < 148 THROW(MyException) --- > ? STORE_LOCAL(value ex5) @@ -222,15 +217,15 @@ > 154 LOAD_LOCAL(value x3) > 154 IS_INSTANCE REF(class MyException) > 154 CZJUMP (BOOL)NE ? 5 : 11 -1050,1052d1141 +1040,1042d1134 < 145 JUMP 4 < < 4: -1285c1374 +1275c1367 < blocks: [1,2,3,4,5,7] --- > blocks: [1,2,3,4,5,7,8] -1309c1398,1405 +1299c1391,1398 < 38 THROW(IllegalArgumentException) --- > ? STORE_LOCAL(value e) @@ -241,16 +236,16 @@ > 42 CONSTANT("IllegalArgumentException") > 42 CALL_METHOD scala.Predef.println (dynamic) > 42 JUMP 2 -1358c1454 +1348c1447 < blocks: [1,2,3,4,5,8,11,13,14,16,17,19] --- > blocks: [1,2,3,5,8,11,13,14,16,17,19,20] -1382c1478,1479 +1372c1471,1472 < 203 THROW(MyException) --- > ? STORE_LOCAL(value ex5) > ? JUMP 20 -1402c1499,1508 +1392c1492,1501 < 209 THROW(MyException) --- > ? STORE_LOCAL(value ex5) @@ -263,15 +258,15 @@ > 212 LOAD_LOCAL(value x3) > 212 IS_INSTANCE REF(class MyException) > 212 CZJUMP (BOOL)NE ? 5 : 11 -1415,1417d1520 +1405,1407d1513 < 200 JUMP 4 < < 4: -1477c1580 +1467c1573 < blocks: [1,2,3,4,5,7] --- > blocks: [1,2,3,4,5,7,8] -1501c1604,1611 +1491c1597,1604 < 58 THROW(IllegalArgumentException) --- > ? STORE_LOCAL(value e) @@ -282,11 +277,11 @@ > 62 CONSTANT("RuntimeException") > 62 CALL_METHOD scala.Predef.println (dynamic) > 62 JUMP 2 -1550c1660 +1540c1653 < blocks: [1,2,3,4] --- > blocks: [1,2,3,4,5] -1570c1680,1685 +1560c1673,1678 < 229 THROW(MyException) --- > ? JUMP 5 @@ -295,19 +290,19 @@ > ? LOAD_LOCAL(variable monitor1) > 228 MONITOR_EXIT > 228 THROW(Throwable) -1576c1691 +1566c1684 < ? THROW(Throwable) --- > 228 THROW(Throwable) -1604c1719 +1594c1712 < locals: value args, variable result, variable monitor2, variable monitorResult1 --- > locals: value exception$1, value args, variable result, variable monitor2, variable monitorResult1 -1606c1721 +1596c1714 < blocks: [1,2,3,4] --- > blocks: [1,2,3,4,5] -1629c1744,1752 +1619c1737,1745 < 245 THROW(MyException) --- > ? STORE_LOCAL(value exception$1) @@ -319,7 +314,7 @@ > ? LOAD_LOCAL(variable monitor2) > 244 MONITOR_EXIT > 244 THROW(Throwable) -1635c1758 +1625c1751 < ? THROW(Throwable) --- > 244 THROW(Throwable) diff --git a/test/files/run/origins.check b/test/files/run/origins.check index ffbf1c1f44..b12cb6e38f 100644 --- a/test/files/run/origins.check +++ b/test/files/run/origins.check @@ -1,5 +1,5 @@ ->> Origins goxbox.Socks.boop logged 65 calls from 3 distinguished sources. +>> Origins tag 'boop' logged 65 calls from 3 distinguished sources. 50 Test$$anonfun$f3$1.apply(origins.scala:16) 10 Test$$anonfun$f2$1.apply(origins.scala:15) diff --git a/test/files/run/origins.scala b/test/files/run/origins.scala index 9dc6071c7b..0ad92297f5 100644 --- a/test/files/run/origins.scala +++ b/test/files/run/origins.scala @@ -2,7 +2,7 @@ import scala.reflect.internal.util.Origins package goxbox { object Socks { - val origins = Origins[Socks.type]("boop") + val origins = Origins("boop") def boop(x: Int): Int = origins { 5 } } diff --git a/test/files/run/t3097.check b/test/files/run/t3097.check new file mode 100644 index 0000000000..63695f771b --- /dev/null +++ b/test/files/run/t3097.check @@ -0,0 +1 @@ +atomic diff --git a/test/files/run/t3097.scala b/test/files/run/t3097.scala new file mode 100644 index 0000000000..4aaf8056ca --- /dev/null +++ b/test/files/run/t3097.scala @@ -0,0 +1,18 @@ +sealed trait ISimpleValue + +sealed trait IListValue extends ISimpleValue +sealed trait IAtomicValue[O] extends ISimpleValue + +sealed trait IAbstractDoubleValue[O] extends IAtomicValue[O] +sealed trait IDoubleValue extends IAbstractDoubleValue[Double] + +case class ListValue(val items: List[IAtomicValue[_]]) extends IListValue +class DoubleValue(val data: Double) extends IDoubleValue + +object Test extends App { + // match is exhaustive + (new DoubleValue(1): ISimpleValue) match { + case m: IListValue => println("list") + case a: IAtomicValue[_] => println("atomic") + } +} diff --git a/test/files/run/t3761-overload-byname.check b/test/files/run/t3761-overload-byname.check new file mode 100644 index 0000000000..ab7eff0d8a --- /dev/null +++ b/test/files/run/t3761-overload-byname.check @@ -0,0 +1,12 @@ +hello! +hello working world +goodnight! +goodnight moon, nobody, noises everywhere +0 +1 +0 +1 +0 +1 +0 +1 diff --git a/test/files/run/t3761-overload-byname.scala b/test/files/run/t3761-overload-byname.scala new file mode 100644 index 0000000000..a52d866097 --- /dev/null +++ b/test/files/run/t3761-overload-byname.scala @@ -0,0 +1,39 @@ + +class OverTheTop { + def info0(m: String) = m + "!" + def info0(m: String, args: Any*) = m +" "+ args.mkString(" ") + + // as reported + def info1(m: =>String) = m + "!" + def info1(m: =>String, args: Any*) = m +" "+ args.mkString(", ") + + // @lrytz + def m[A](x: => Int) = 0; def m[A](x: => Int, xs: Int*) = 1 + + def m1(x: => Int, s: String) = 0 + def m1(x: => Int, s: Object) = 1 + + def m2(x: => Int, s: String) = 0 + def m2(x: => AnyVal, s: Object) = 1 + + def m3(x: => Int, s: String) = 0 + def m3(x: => Any, s: Object) = 1 +} + +object Test { + def main(args: Array[String]) { + val top = new OverTheTop + println(top.info0("hello")) + println(top.info0("hello","working","world")) + println(top.info1("goodnight")) + println(top.info1("goodnight", "moon", "nobody", "noises everywhere")) + println(top.m(17)) + println(top.m(17,19)) + println(top.m1(1, "two")) + println(top.m1(1, new Object())) + println(top.m2(1, "")) + println(top.m2(1d, "")) + println(top.m3(1, "")) + println(top.m3("", "")) + } +} diff --git a/test/files/run/t5125.check b/test/files/run/t5125.check new file mode 100644 index 0000000000..d8a0565005 --- /dev/null +++ b/test/files/run/t5125.check @@ -0,0 +1,4 @@ +public void O1$.f(java.lang.String[]) +public void O1$.f(scala.collection.Seq) +public void O2$.f(java.lang.String[]) +public void O2$.f(scala.collection.Seq) diff --git a/test/files/run/t5125.scala b/test/files/run/t5125.scala new file mode 100644 index 0000000000..7ec2b929d9 --- /dev/null +++ b/test/files/run/t5125.scala @@ -0,0 +1,24 @@ +object O1 { + def instance = this + @scala.annotation.varargs + def f(values:String*) = println("Calling O1.f(): " + values) +} + +object O2 { + def instance = this + @scala.annotation.varargs + def f(values:String*) = println("Calling O2.f(): " + values) + // uncommenting g() results in errors in A.java + def g(): String => Int = s => s.hashCode +} + +object Test extends App { + def check(c: Class[_]) { + val methodName = "f" + val methods = c.getDeclaredMethods.filter(_.getName == methodName) + println(methods.map(_.toString).sorted.mkString("\n")) + } + + check(O1.getClass) + check(O2.getClass) +}
\ No newline at end of file diff --git a/test/files/run/t5125b.check b/test/files/run/t5125b.check new file mode 100644 index 0000000000..ddbf908f04 --- /dev/null +++ b/test/files/run/t5125b.check @@ -0,0 +1,7 @@ +public void C1.f(java.lang.String[]) +public void C1.f(scala.collection.Seq) +public void C2.f(java.lang.String[]) +public void C2.f(scala.collection.Seq) +public void C2$C3.f(java.lang.String[]) +public void C2$C3.f(scala.collection.Seq) +public void C4.f(scala.collection.Seq) diff --git a/test/files/run/t5125b.scala b/test/files/run/t5125b.scala new file mode 100644 index 0000000000..29c08fee4c --- /dev/null +++ b/test/files/run/t5125b.scala @@ -0,0 +1,37 @@ +class C1 { + @scala.annotation.varargs + def f(values:String*) = println("Calling C1.f(): " + values) +} + +class C2 { + @scala.annotation.varargs + def f(values:String*) = println("Calling C2.f(): " + values) + def g(): String => Int = s => s.hashCode + + class C3 { + @scala.annotation.varargs + def f(values:String*) = println("Calling C3.f(): " + values) + } +} + +class C4 { + def f(values: String*) = println("Calling C4.f(): " + values) + + locally { + @scala.annotation.varargs + def f(values: String*) = println("Calling C4.<locally>.f(): " + values) + } +} + +object Test extends App { + def check(c: Class[_]) { + val methodName = "f" + val methods = c.getDeclaredMethods.filter(_.getName == methodName) + println(methods.map(_.toString).sorted.mkString("\n")) + } + + check(classOf[C1]) + check(classOf[C2]) + check(classOf[C2#C3]) + check(classOf[C4]) +} diff --git a/test/files/run/t5428.check b/test/files/run/t5428.check new file mode 100644 index 0000000000..7b4b1d6558 --- /dev/null +++ b/test/files/run/t5428.check @@ -0,0 +1 @@ +Stack(8, 7, 6, 5, 4, 3)
\ No newline at end of file diff --git a/test/files/run/t5428.scala b/test/files/run/t5428.scala new file mode 100644 index 0000000000..106bb7fc31 --- /dev/null +++ b/test/files/run/t5428.scala @@ -0,0 +1,29 @@ + + + +import collection.mutable.{Stack, StackProxy} + + + +class A extends StackProxy[Int] { + val self = Stack[Int]() +} + + +object Test { + + def main(args: Array[String]) { + val a = new A + + a push 3 + a push 4 + a push 5 + + a.push(6, 7, 8) + + println(a) + + a pop + } + +} diff --git a/test/files/run/t5804.check b/test/files/run/t5804.check new file mode 100644 index 0000000000..3ccc1c24d3 --- /dev/null +++ b/test/files/run/t5804.check @@ -0,0 +1,4 @@ +128 +16 +128 +32
\ No newline at end of file diff --git a/test/files/run/t5804.scala b/test/files/run/t5804.scala new file mode 100644 index 0000000000..b96a736035 --- /dev/null +++ b/test/files/run/t5804.scala @@ -0,0 +1,32 @@ + + +import collection.mutable._ + + +object Test { + + def main(args: Array[String]) { + class CustomHashMap extends HashMap[Int, Int] { + override def initialSize = 65 + + println(table.length) + } + + new CustomHashMap + new HashMap { + println(table.length) + } + + class CustomHashSet extends HashSet[Int] { + override def initialSize = 96 + + println(table.length) + } + + new CustomHashSet + new HashSet { + println(table.length) + } + } + +} diff --git a/test/pending/neg/t5008.scala b/test/pending/neg/t5008.scala new file mode 100644 index 0000000000..2b20bcfe12 --- /dev/null +++ b/test/pending/neg/t5008.scala @@ -0,0 +1,165 @@ +// These are members of class bar.C, completely unrelated to class foo.A. +// The types shown below include types defined within foo.A which are: +// +// - qualified private +// - qualified protected +// - object protected +// +// val a : foo.A = { /* compiled code */ } +// val xprot1 : java.lang.Object with foo.A.FooProt1 = { /* compiled code */ } +// val xprot2 : java.lang.Object with foo.A.FooProt2 = { /* compiled code */ } +// val xprot3 : java.lang.Object with foo.A.FooProt3 = { /* compiled code */ } +// val xprot4 : java.lang.Object with foo.A.FooProt4 = { /* compiled code */ } +// val xpriv3 : java.lang.Object with foo.A.FooPriv3 = { /* compiled code */ } +// val xpriv4 : java.lang.Object with foo.A.FooPriv4 = { /* compiled code */ } +// +// Indeed it will tell me a type which I cannot access: +// +// scala> new bar.C +// res0: bar.C = bar.C@1339a0dc +// +// scala> res0.xpriv3 +// res1: java.lang.Object with res0.a.FooPriv3 = bar.C$$anon$29@39556aec +// +// scala> new res0.a.FooPriv3 +// <console>:9: error: trait FooPriv3 in class A cannot be accessed in foo.A +// new res0.a.FooPriv3 +// ^ +// Looking at how the compiler prints the types of those vals, one +// develops a suspicion how some of it is being allowed: +// +// val xpriv4: C.this.a.FooPriv4 +// val xpriv3: C.this.a.FooPriv3 +// val xprot4: C.this.a.FooProt4 +// val xprot3: C.this.a.FooProt3 +// val xprot2: C.this.a.FooProt2 +// val xprot1: C.this.a.FooProt1 +// +// That is, "this" is in the prefix somewhere, it's just not a "this" +// which has any bearing. + +package foo { + class A { + trait Foo + + protected trait FooProt1 + protected[this] trait FooProt2 + protected[foo] trait FooProt3 + protected[A] trait FooProt4 + + private trait FooPriv1 + private[this] trait FooPriv2 + private[foo] trait FooPriv3 + private[A] trait FooPriv4 + + type BarProt1 = FooProt1 + type BarProt2 = FooProt2 + type BarProt3 = FooProt3 + type BarProt4 = FooProt4 + + // type BarPriv1 = FooPriv1 + // type BarPriv2 = FooPriv2 + type BarPriv3 = FooPriv3 + type BarPriv4 = FooPriv4 + + def fprot1(x: FooProt1) = x + def fprot2(x: FooProt2) = x + def fprot3(x: FooProt3) = x + def fprot4(x: FooProt4) = x + + // def fpriv1(x: FooPriv1) = x + // def fpriv2(x: FooPriv2) = x + def fpriv3(x: FooPriv3) = x + def fpriv4(x: FooPriv4) = x + + val yprot1 = new FooProt1 { } + val yprot2 = new FooProt2 { } + val yprot3 = new FooProt3 { } + val yprot4 = new FooProt4 { } + + // val ypriv1 = new FooPriv1 { } + // val ypriv2 = new FooPriv2 { } + val ypriv3 = new FooPriv3 { } + val ypriv4 = new FooPriv4 { } + + def fpriv_alt1(x: FooPriv1) = 0 // !!! isn't the private type now in the signature of the (public) method? + def fpriv_alt2(x: FooPriv2) = 0 // !!! isn't the private[this] type now in the signature of the (public) method? + } + // Same package, subclass + class B extends A { + val xprot1 = new BarProt1 { } + val xprot2 = new BarProt2 { } + val xprot3 = new BarProt3 { } + val xprot4 = new BarProt4 { } + + // val xpriv1 = new BarPriv1 { } + // val xpriv2 = new BarPriv2 { } + val xpriv3 = new BarPriv3 { } + val xpriv4 = new BarPriv4 { } + + override def fprot1(x: BarProt1) = x + override def fprot2(x: BarProt2) = x + override def fprot3(x: BarProt3) = x + override def fprot4(x: BarProt4) = x + + // override def fpriv1(x: BarPriv1) = x + // override def fpriv2(x: BarPriv2) = x + override def fpriv3(x: BarPriv3) = x + override def fpriv4(x: BarPriv4) = x + } + // Same package, unrelated class + class C { + val a = new A + import a._ + + val xprot1 = new BarProt1 { } + val xprot2 = new BarProt2 { } + val xprot3 = new BarProt3 { } + val xprot4 = new BarProt4 { } + + // val xpriv1 = new BarPriv1 { } + // val xpriv2 = new BarPriv2 { } + val xpriv3 = new BarPriv3 { } + val xpriv4 = new BarPriv4 { } + } +} + +package bar { + // Different package, subclass + class B extends foo.A { + val xprot1 = new BarProt1 { } + val xprot2 = new BarProt2 { } + val xprot3 = new BarProt3 { } + val xprot4 = new BarProt4 { } + + // val xpriv1 = new BarPriv1 { } + // val xpriv2 = new BarPriv2 { } + val xpriv3 = new BarPriv3 { } + val xpriv4 = new BarPriv4 { } + + override def fprot1(x: BarProt1) = x + override def fprot2(x: BarProt2) = x + override def fprot3(x: BarProt3) = x + override def fprot4(x: BarProt4) = x + + // override def fpriv1(x: BarPriv1) = x + // override def fpriv2(x: BarPriv2) = x + override def fpriv3(x: BarPriv3) = x + override def fpriv4(x: BarPriv4) = x + } + // Different package, unrelated class + class C { + val a = new foo.A + import a._ + + val xprot1 = new BarProt1 { } + val xprot2 = new BarProt2 { } + val xprot3 = new BarProt3 { } + val xprot4 = new BarProt4 { } + + // val xpriv1 = new BarPriv1 { } + // val xpriv2 = new BarPriv2 { } + val xpriv3 = new BarPriv3 { } + val xpriv4 = new BarPriv4 { } + } +} diff --git a/test/files/pos/no-widen-locals.scala b/test/pending/pos/no-widen-locals.scala index 013e63f0a2..013e63f0a2 100644 --- a/test/files/pos/no-widen-locals.scala +++ b/test/pending/pos/no-widen-locals.scala diff --git a/test/pending/pos/t4649.flags b/test/pending/pos/t4649.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/pending/pos/t4649.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/pending/pos/t4649.scala b/test/pending/pos/t4649.scala new file mode 100644 index 0000000000..0d6caa8d7a --- /dev/null +++ b/test/pending/pos/t4649.scala @@ -0,0 +1,6 @@ +object Test { + // @annotation.tailrec + def lazyFilter[E](s: Stream[E], p: E => Boolean): Stream[E] = s match { + case h #:: t => if (p(h)) h #:: lazyFilter(t, p) else lazyFilter(t, p) + } +} diff --git a/test/pending/run/partial-anyref-spec.check b/test/pending/run/partial-anyref-spec.check new file mode 100644 index 0000000000..26e41933e7 --- /dev/null +++ b/test/pending/run/partial-anyref-spec.check @@ -0,0 +1,13 @@ +Fn$mcII$sp +Fn$mcLI$sp +Fn$mcLI$sp +Fn$mcIL$sp +Fn +Fn +Fn$mcIL$sp +Fn +Fn +Fn3 +Fn3$mcLIDF$sp +Fn3$mcBIDF$sp +Fn3 diff --git a/test/pending/run/partial-anyref-spec.scala b/test/pending/run/partial-anyref-spec.scala new file mode 100644 index 0000000000..49ed514f03 --- /dev/null +++ b/test/pending/run/partial-anyref-spec.scala @@ -0,0 +1,31 @@ +class Fn[@specialized(Int, AnyRef) -T, @specialized(Int, AnyRef) +R] { + override def toString = getClass.getName +} + +class Fn3[ + @specialized(Int, AnyRef) -T1, + @specialized(Double, AnyRef) -T2, + @specialized(Float) -T3, + @specialized(Byte, AnyRef) +R +] { + override def toString = getClass.getName +} + +object Test { + def main(args: Array[String]): Unit = { + println(new Fn[Int, Int]) + println(new Fn[Int, Byte]) + println(new Fn[Int, AnyRef]) + println(new Fn[Byte, Int]) + println(new Fn[Byte, Byte]) + println(new Fn[Byte, AnyRef]) + println(new Fn[AnyRef, Int]) + println(new Fn[AnyRef, Byte]) + println(new Fn[AnyRef, AnyRef]) + + println(new Fn3[Int, Int, Int, Int]) + println(new Fn3[Int, Double, Float, Int]) + println(new Fn3[Int, Double, Float, Byte]) + println(new Fn3[AnyRef, Double, AnyRef, Int]) + } +} diff --git a/test/pending/run/t3899.check b/test/pending/run/t3899.check new file mode 100644 index 0000000000..c317608eab --- /dev/null +++ b/test/pending/run/t3899.check @@ -0,0 +1,4 @@ +a,b +a,b +a,b +a,b diff --git a/test/pending/run/t3899/Base_1.java b/test/pending/run/t3899/Base_1.java new file mode 100644 index 0000000000..114cc0b7a6 --- /dev/null +++ b/test/pending/run/t3899/Base_1.java @@ -0,0 +1,5 @@ +public class Base_1 { + public String[] varargs1(String... as) { + return as; + } +} diff --git a/test/pending/run/t3899/Derived_2.scala b/test/pending/run/t3899/Derived_2.scala new file mode 100644 index 0000000000..bb4e53784d --- /dev/null +++ b/test/pending/run/t3899/Derived_2.scala @@ -0,0 +1,30 @@ +trait T extends Base_1 { + def t1(as: String*): Array[String] = { + varargs1(as: _*) + } + def t2(as: String*): Array[String] = { + // This is the bug reported in the ticket. + super.varargs1(as: _*) + } +} + +class C extends Base_1 { + def c1(as: String*): Array[String] = { + varargs1(as: _*) + } + def c2(as: String*): Array[String] = { + super.varargs1(as: _*) + } +} + + +object Test extends App { + val t = new T {} + println(t.t1("a", "b").mkString(",")) + println(t.t2("a", "b").mkString(",")) + + val c = new C {} + println(c.c1("a", "b").mkString(",")) + println(c.c2("a", "b").mkString(",")) + +} |