From 3307c3771777cf17d5b4d059726a1b484923d042 Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Fri, 22 Jul 2011 16:34:35 +0000 Subject: Backport from trunk of a large batch of revisions: 24909,24919,24941,24961,24963,24965,24981,24984,24986,24987,24999, 25000,25001,25002,25003,25004,25005,25006,25007,25008,25009,25010, 25015,25028,25029,25030,25031,25033,25037,25038,25039,25040,25041, 25044,25045,25046,25050,25052,25053,25054,25055,25057,25058,25059, 25061,25062,25063,25065,25066,25069,25070,25071,25072,25074,25075, 25076,25080,25081,25082,25083,25085,25087,25088,25090,25091,25092, 25093,25094,25095,25096,25097,25098,25099,25100,25101,25110,25111, 25112,25113,25114,25117,25119,25122,25124,25125,25126,25127,25128, 25130,25132,25133,25134,25135,25136,25137,25138,25138,25139,25140, 25141,25142,25144,25145,25146,25148,25149,25152,25153,25158,25160, 25161,25162,25164,25167,25169,25170,25171,25172,25202,25204,25208, 25209,25252 --- test/files/jvm/actor-sync-send-timeout.scala | 47 ++ test/files/jvm/manifests.check | 2 +- test/files/neg/abstract-inaccessible.check | 13 + test/files/neg/abstract-inaccessible.flags | 1 + test/files/neg/abstract-inaccessible.scala | 9 + test/files/neg/bug278.check | 2 +- test/files/neg/bug4419.check | 4 + test/files/neg/bug4419.scala | 3 + test/files/neg/bug4533.check | 4 - test/files/neg/bug4533.scala | 8 - test/files/neg/bug4584.check | 4 + test/files/neg/bug4584.scala | 1 + test/files/neg/bug4727.check | 11 + test/files/neg/bug4727.scala | 7 + test/files/neg/bug588.check | 4 +- test/files/neg/bug752.check | 4 +- test/files/neg/divergent-implicit.check | 6 +- test/files/neg/nullary-override.check | 4 + test/files/neg/nullary-override.flags | 1 + test/files/neg/nullary-override.scala | 3 + test/files/neg/t0003.check | 4 +- test/files/neg/t0015.check | 2 +- test/files/neg/t2179.check | 9 - test/files/neg/t2179.scala | 3 - test/files/neg/t2641.check | 12 +- test/files/neg/t3507.check | 2 +- test/files/neg/t3774.check | 7 - test/files/neg/t3774.scala | 5 - test/files/neg/unit2anyref.check | 4 +- test/files/neg/variances.check | 2 +- test/files/pos/bug1439.flags | 1 + test/files/pos/bug1439.scala | 8 + test/files/pos/bug2094.scala | 31 + test/files/pos/bug3048.scala | 8 + test/files/pos/bug3343.scala | 15 + test/files/pos/bug3528.scala | 8 + test/files/pos/bug4018.scala | 15 + test/files/pos/bug4237.scala | 6 + test/files/pos/bug4501.scala | 14 + test/files/pos/bug4553.scala | 11 + test/files/pos/bug4731.scala | 14 + test/files/pos/hk-infer.scala | 37 ++ test/files/pos/no-widen-locals.scala | 17 - test/files/pos/spec-List.scala | 869 --------------------------- test/files/pos/t1439.scala | 7 - test/files/pos/t2179.scala | 3 + test/files/pos/t3774.scala | 5 + test/files/pos/t4547.scala | 4 + test/files/pos/t4593.scala | 20 + test/files/pos/t4692.scala | 27 + test/files/pos/widen-existential.scala | 7 + test/files/run/TestFlatMap.scala | 29 + test/files/run/bug2308a.check | 1 + test/files/run/bug2308a.scala | 7 + test/files/run/bug4110.check | 2 + test/files/run/bug4110.scala | 11 + test/files/run/bug4570.check | 1 + test/files/run/bug4570.scala | 8 + test/files/run/bug4656.check | 1 + test/files/run/bug4656.scala | 13 + test/files/run/bug4660.scala | 11 + test/files/run/bug4697.check | 1 + test/files/run/bug4697.scala | 8 + test/files/run/constrained-types.check | 2 +- test/files/run/getClassTest.check | 18 + test/files/run/getClassTest.scala | 66 ++ test/files/run/null-and-intersect.check | 9 + test/files/run/null-and-intersect.scala | 34 ++ test/files/run/view-headoption.check | 28 + test/files/run/view-headoption.scala | 18 + test/files/scalacheck/range.scala | 7 + test/files/specialized/fft.check | 2 +- 72 files changed, 644 insertions(+), 948 deletions(-) create mode 100644 test/files/jvm/actor-sync-send-timeout.scala create mode 100644 test/files/neg/abstract-inaccessible.check create mode 100644 test/files/neg/abstract-inaccessible.flags create mode 100644 test/files/neg/abstract-inaccessible.scala create mode 100644 test/files/neg/bug4419.check create mode 100644 test/files/neg/bug4419.scala delete mode 100644 test/files/neg/bug4533.check delete mode 100644 test/files/neg/bug4533.scala create mode 100644 test/files/neg/bug4584.check create mode 100644 test/files/neg/bug4584.scala create mode 100644 test/files/neg/bug4727.check create mode 100644 test/files/neg/bug4727.scala create mode 100644 test/files/neg/nullary-override.check create mode 100644 test/files/neg/nullary-override.flags create mode 100644 test/files/neg/nullary-override.scala delete mode 100644 test/files/neg/t2179.check delete mode 100755 test/files/neg/t2179.scala delete mode 100644 test/files/neg/t3774.check delete mode 100644 test/files/neg/t3774.scala create mode 100644 test/files/pos/bug1439.flags create mode 100644 test/files/pos/bug1439.scala create mode 100644 test/files/pos/bug2094.scala create mode 100644 test/files/pos/bug3048.scala create mode 100644 test/files/pos/bug3343.scala create mode 100644 test/files/pos/bug3528.scala create mode 100644 test/files/pos/bug4018.scala create mode 100644 test/files/pos/bug4237.scala create mode 100644 test/files/pos/bug4501.scala create mode 100755 test/files/pos/bug4553.scala create mode 100644 test/files/pos/bug4731.scala create mode 100644 test/files/pos/hk-infer.scala delete mode 100644 test/files/pos/no-widen-locals.scala delete mode 100644 test/files/pos/spec-List.scala delete mode 100644 test/files/pos/t1439.scala create mode 100755 test/files/pos/t2179.scala create mode 100644 test/files/pos/t3774.scala create mode 100644 test/files/pos/t4547.scala create mode 100644 test/files/pos/t4593.scala create mode 100644 test/files/pos/t4692.scala create mode 100644 test/files/pos/widen-existential.scala create mode 100644 test/files/run/TestFlatMap.scala create mode 100644 test/files/run/bug2308a.check create mode 100644 test/files/run/bug2308a.scala create mode 100644 test/files/run/bug4110.check create mode 100644 test/files/run/bug4110.scala create mode 100644 test/files/run/bug4570.check create mode 100644 test/files/run/bug4570.scala create mode 100644 test/files/run/bug4656.check create mode 100644 test/files/run/bug4656.scala create mode 100644 test/files/run/bug4660.scala create mode 100644 test/files/run/bug4697.check create mode 100644 test/files/run/bug4697.scala create mode 100644 test/files/run/getClassTest.check create mode 100644 test/files/run/getClassTest.scala create mode 100644 test/files/run/null-and-intersect.check create mode 100644 test/files/run/null-and-intersect.scala create mode 100644 test/files/run/view-headoption.check create mode 100644 test/files/run/view-headoption.scala (limited to 'test/files') diff --git a/test/files/jvm/actor-sync-send-timeout.scala b/test/files/jvm/actor-sync-send-timeout.scala new file mode 100644 index 0000000000..ed330900b2 --- /dev/null +++ b/test/files/jvm/actor-sync-send-timeout.scala @@ -0,0 +1,47 @@ +import scala.actors.Actor + +/* This test is a regression test for SI-4759. + */ +object Test { + val Runs = 5 + + def main(args: Array[String]) = { + var i = 0 + while (i < Runs) { + i += 1 + A1 ! 1 + Thread.sleep(500) + } + //println("done sending to A1") + } +} + +object A2 extends Actor { + this.start() + def act() { + loop { + react { + case 'stop => + //println("A2 exiting") + exit() + case _ => + } + } + } +} + +object A1 extends Actor { + this.start() + def act() { + var i = 0 + loopWhile(i < Test.Runs) { + i += 1 + react { + case any => + A2 !? (500, any) + if (i == Test.Runs) + A2 ! 'stop + } + } + } +} diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check index 3b8ca5b5b1..54f504b929 100644 --- a/test/files/jvm/manifests.check +++ b/test/files/jvm/manifests.check @@ -29,7 +29,7 @@ x=Foo, m=Foo[scala.collection.immutable.List[Int]] x=Foo, m=Foo[Foo[Int]] x=Foo, m=Foo[scala.collection.immutable.List[Foo[Int]]] -x=Test1$$anon$1, m=Test1$$anon$1 +x=Test1$$anon$1, m=Object with Bar[java.lang.String] ()=() true=true diff --git a/test/files/neg/abstract-inaccessible.check b/test/files/neg/abstract-inaccessible.check new file mode 100644 index 0000000000..42b98ac026 --- /dev/null +++ b/test/files/neg/abstract-inaccessible.check @@ -0,0 +1,13 @@ +abstract-inaccessible.scala:5: error: method implementMe in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to provide a concrete implementation of implementMe. + def implementMe(f: Int => (String, Bippy)): Unit + ^ +abstract-inaccessible.scala:6: error: method overrideMe in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to override overrideMe. + def overrideMe[T <: Bippy](x: T): T = x + ^ +abstract-inaccessible.scala:7: error: method overrideMeAlso in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to override overrideMeAlso. + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + ^ +three errors found diff --git a/test/files/neg/abstract-inaccessible.flags b/test/files/neg/abstract-inaccessible.flags new file mode 100644 index 0000000000..6c1dd108ae --- /dev/null +++ b/test/files/neg/abstract-inaccessible.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint \ No newline at end of file diff --git a/test/files/neg/abstract-inaccessible.scala b/test/files/neg/abstract-inaccessible.scala new file mode 100644 index 0000000000..3c80f30522 --- /dev/null +++ b/test/files/neg/abstract-inaccessible.scala @@ -0,0 +1,9 @@ +package foo { + private[foo] trait Bippy { } + + trait YourTrait { + def implementMe(f: Int => (String, Bippy)): Unit + def overrideMe[T <: Bippy](x: T): T = x + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + } +} diff --git a/test/files/neg/bug278.check b/test/files/neg/bug278.check index ad0a97371e..b1041b7895 100644 --- a/test/files/neg/bug278.check +++ b/test/files/neg/bug278.check @@ -1,5 +1,5 @@ bug278.scala:5: error: overloaded method value a with alternatives: - => (C.this.A) => Unit + => C.this.A => Unit => () => Unit does not take type parameters a[A] diff --git a/test/files/neg/bug4419.check b/test/files/neg/bug4419.check new file mode 100644 index 0000000000..488be9a591 --- /dev/null +++ b/test/files/neg/bug4419.check @@ -0,0 +1,4 @@ +bug4419.scala:2: error: forward reference extends over definition of value b + { val b = a; val a = 1 } + ^ +one error found diff --git a/test/files/neg/bug4419.scala b/test/files/neg/bug4419.scala new file mode 100644 index 0000000000..38a34be489 --- /dev/null +++ b/test/files/neg/bug4419.scala @@ -0,0 +1,3 @@ +class A { + { val b = a; val a = 1 } +} \ No newline at end of file diff --git a/test/files/neg/bug4533.check b/test/files/neg/bug4533.check deleted file mode 100644 index b405619831..0000000000 --- a/test/files/neg/bug4533.check +++ /dev/null @@ -1,4 +0,0 @@ -bug4533.scala:6: error: trait GenSetLike in package collection cannot be accessed in package collection - def statusByAlarms(alarms: GenSetLike[FooAlarm]) = println("hello") - ^ -one error found diff --git a/test/files/neg/bug4533.scala b/test/files/neg/bug4533.scala deleted file mode 100644 index 425c958328..0000000000 --- a/test/files/neg/bug4533.scala +++ /dev/null @@ -1,8 +0,0 @@ -package demo - -import scala.collection._ - -class CrashDemo { - def statusByAlarms(alarms: GenSetLike[FooAlarm]) = println("hello") -} -class FooAlarm { } diff --git a/test/files/neg/bug4584.check b/test/files/neg/bug4584.check new file mode 100644 index 0000000000..0008d9efa5 --- /dev/null +++ b/test/files/neg/bug4584.check @@ -0,0 +1,4 @@ +bug4584.scala:1: error: incomplete unicode escape +class A { val \u2 + ^ +one error found diff --git a/test/files/neg/bug4584.scala b/test/files/neg/bug4584.scala new file mode 100644 index 0000000000..b34aba91a2 --- /dev/null +++ b/test/files/neg/bug4584.scala @@ -0,0 +1 @@ +class A { val \u2 \ No newline at end of file diff --git a/test/files/neg/bug4727.check b/test/files/neg/bug4727.check new file mode 100644 index 0000000000..cac35b1548 --- /dev/null +++ b/test/files/neg/bug4727.check @@ -0,0 +1,11 @@ +bug4727.scala:5: error: type mismatch; + found : Null + required: Int +Note that implicit conversions are not applicable because they are ambiguous: + both method Integer2intNullConflict in class LowPriorityImplicits of type (x: Null)Int + and method Integer2int in object Predef of type (x: java.lang.Integer)Int + are possible conversion functions from Null to Int +Error occurred in an application involving default arguments. + new C[Int] + ^ +one error found diff --git a/test/files/neg/bug4727.scala b/test/files/neg/bug4727.scala new file mode 100644 index 0000000000..40c06713ca --- /dev/null +++ b/test/files/neg/bug4727.scala @@ -0,0 +1,7 @@ +class C[T](x : T = null) + +object Test { + def main(args: Array[String]): Unit = { + new C[Int] + } +} diff --git a/test/files/neg/bug588.check b/test/files/neg/bug588.check index 5f55c95619..8c01ac5b09 100644 --- a/test/files/neg/bug588.check +++ b/test/files/neg/bug588.check @@ -1,6 +1,6 @@ bug588.scala:3: error: double definition: -method visit:(f: (Int) => String)Boolean and -method visit:(f: (Int) => Unit)Boolean at line 2 +method visit:(f: Int => String)Boolean and +method visit:(f: Int => Unit)Boolean at line 2 have same type after erasure: (f: Function1)Boolean def visit(f: Int => String): Boolean ^ diff --git a/test/files/neg/bug752.check b/test/files/neg/bug752.check index dddab530e4..9262f38f01 100644 --- a/test/files/neg/bug752.check +++ b/test/files/neg/bug752.check @@ -1,6 +1,6 @@ bug752.scala:6: error: type mismatch; - found : (String) => Unit - required: (Int) => Unit + found : String => Unit + required: Int => Unit f(g _) ^ one error found diff --git a/test/files/neg/divergent-implicit.check b/test/files/neg/divergent-implicit.check index 07af8510d9..5f20df1b91 100644 --- a/test/files/neg/divergent-implicit.check +++ b/test/files/neg/divergent-implicit.check @@ -3,15 +3,15 @@ divergent-implicit.scala:4: error: type mismatch; required: String val x1: String = 1 ^ -divergent-implicit.scala:5: error: diverging implicit expansion for type (Int) => String +divergent-implicit.scala:5: error: diverging implicit expansion for type Int => String starting with method cast in object Test1 val x2: String = cast[Int, String](1) ^ -divergent-implicit.scala:14: error: diverging implicit expansion for type (Test2.Baz) => Test2.Bar +divergent-implicit.scala:14: error: diverging implicit expansion for type Test2.Baz => Test2.Bar starting with method baz2bar in object Test2 val x: Bar = new Foo ^ -divergent-implicit.scala:15: error: diverging implicit expansion for type (Test2.Foo) => Test2.Bar +divergent-implicit.scala:15: error: diverging implicit expansion for type Test2.Foo => Test2.Bar starting with method foo2bar in object Test2 val y: Bar = new Baz ^ diff --git a/test/files/neg/nullary-override.check b/test/files/neg/nullary-override.check new file mode 100644 index 0000000000..6b2ded2d4a --- /dev/null +++ b/test/files/neg/nullary-override.check @@ -0,0 +1,4 @@ +nullary-override.scala:2: error: non-nullary method overrides nullary method +class B extends A { override def x(): Int = 4 } + ^ +one error found diff --git a/test/files/neg/nullary-override.flags b/test/files/neg/nullary-override.flags new file mode 100644 index 0000000000..6c1dd108ae --- /dev/null +++ b/test/files/neg/nullary-override.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint \ No newline at end of file diff --git a/test/files/neg/nullary-override.scala b/test/files/neg/nullary-override.scala new file mode 100644 index 0000000000..3eb4784a0c --- /dev/null +++ b/test/files/neg/nullary-override.scala @@ -0,0 +1,3 @@ +class A { def x: Int = 3 } +class B extends A { override def x(): Int = 4 } + diff --git a/test/files/neg/t0003.check b/test/files/neg/t0003.check index fb5bb5671d..1913dde9dd 100644 --- a/test/files/neg/t0003.check +++ b/test/files/neg/t0003.check @@ -1,6 +1,6 @@ t0003.scala:2: error: type mismatch; - found : (A) => (B) => B - required: (A) => B + found : A => B => B + required: A => B def foo[A, B, C](l: List[A], f: A => B=>B, g: B=>B=>C): List[C] = l map (g compose f) ^ one error found diff --git a/test/files/neg/t0015.check b/test/files/neg/t0015.check index eb25fc46c8..43adc22f72 100644 --- a/test/files/neg/t0015.check +++ b/test/files/neg/t0015.check @@ -1,6 +1,6 @@ t0015.scala:5: error: type mismatch; found : () => Nothing - required: (Nothing) => ? + required: Nothing => ? Nil.map(f _) ^ one error found diff --git a/test/files/neg/t2179.check b/test/files/neg/t2179.check deleted file mode 100644 index aa94fabe1f..0000000000 --- a/test/files/neg/t2179.check +++ /dev/null @@ -1,9 +0,0 @@ -t2179.scala:2: error: inferred type arguments [scala.collection.immutable.Seq[Double]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq[Any]]; protected def thisCollection: Seq[Double]{def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}}] do not conform to method reduceLeft's type parameter bounds [B >: List[Double]] - (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) - ^ -t2179.scala:2: error: type mismatch; - found : (Any, Any) => scala.collection.immutable.IndexedSeq[Double] - required: (scala.collection.immutable.Seq[Double]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq[Any]]; protected def thisCollection: Seq[Double]{def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}}, List[Double]) => scala.collection.immutable.Seq[Double]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq[Any]]; protected def thisCollection: Seq[Double]{def companion: scala.collection.generic.GenericCompanion[Seq[Any]]}} - (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) - ^ -two errors found diff --git a/test/files/neg/t2179.scala b/test/files/neg/t2179.scala deleted file mode 100755 index 89e22b6e2a..0000000000 --- a/test/files/neg/t2179.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) -} diff --git a/test/files/neg/t2641.check b/test/files/neg/t2641.check index f19a901859..771624e8d9 100644 --- a/test/files/neg/t2641.check +++ b/test/files/neg/t2641.check @@ -19,7 +19,17 @@ t2641.scala:25: error: something is wrong (wrong class file?): trait ManagedSeq t2641.scala:27: error: something is wrong (wrong class file?): trait ManagedSeq with type parameters [A,Coll] gets applied to arguments [], phase = namer trait Sliced extends Transformed[A] with super.Sliced { ^ +t2641.scala:27: error: illegal inheritance; superclass Any + is not a subclass of the superclass ManagedSeqStrict + of the mixin trait Transformed + trait Sliced extends Transformed[A] with super.Sliced { + ^ +t2641.scala:27: error: illegal inheritance; superclass Any + is not a subclass of the superclass Object + of the mixin trait Sliced + trait Sliced extends Transformed[A] with super.Sliced { + ^ t2641.scala:28: error: value managedIterator is not a member of ManagedSeq override def managedIterator = self.managedIterator slice (from, until) ^ -7 errors found +9 errors found diff --git a/test/files/neg/t3507.check b/test/files/neg/t3507.check index ab38280c1f..8e538e4a8b 100644 --- a/test/files/neg/t3507.check +++ b/test/files/neg/t3507.check @@ -1,4 +1,4 @@ -t3507.scala:13: error: No Manifest available for object _1.b.c. +t3507.scala:13: error: No Manifest available for _1.b.c.type. mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier ^ one error found diff --git a/test/files/neg/t3774.check b/test/files/neg/t3774.check deleted file mode 100644 index cce2d7076c..0000000000 --- a/test/files/neg/t3774.check +++ /dev/null @@ -1,7 +0,0 @@ -t3774.scala:4: error: overloaded method value ++ with alternatives: - [B1 >: List[Int]](xs: scala.collection.GenTraversableOnce[((Int, Int), B1)])scala.collection.immutable.Map[(Int, Int),B1] - [B >: ((Int, Int), List[Int]), That](that: scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Map[(Int, Int),List[Int]],B,That])That - cannot be applied to (scala.collection.immutable.IndexedSeq[((Int, Int), scala.collection.immutable.Range.Inclusive)]) - Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) - ^ -one error found diff --git a/test/files/neg/t3774.scala b/test/files/neg/t3774.scala deleted file mode 100644 index 2869925b01..0000000000 --- a/test/files/neg/t3774.scala +++ /dev/null @@ -1,5 +0,0 @@ -// This used to hang the lub process. Now it rejects the file. This is still not correct, -// but we can solve this only after a redesign of lub a la dot. -object Hang { - Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) -} diff --git a/test/files/neg/unit2anyref.check b/test/files/neg/unit2anyref.check index 2616fd35f9..10fe1861f5 100644 --- a/test/files/neg/unit2anyref.check +++ b/test/files/neg/unit2anyref.check @@ -1,8 +1,8 @@ unit2anyref.scala:2: error: type mismatch; found : Unit required: AnyRef -Note: primitive types are not implicitly converted to AnyRef. -You can safely force boxing by casting x.asInstanceOf[AnyRef]. +Note: Unit is not implicitly converted to AnyRef. You can safely +pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so. val x: AnyRef = () // this should not succeed. ^ one error found diff --git a/test/files/neg/variances.check b/test/files/neg/variances.check index d395e45e4e..4eaab56cef 100644 --- a/test/files/neg/variances.check +++ b/test/files/neg/variances.check @@ -7,7 +7,7 @@ variances.scala:14: error: covariant type A occurs in contravariant position in variances.scala:16: error: covariant type A occurs in invariant position in supertype test.C[A] with ScalaObject of object Baz object Baz extends C[A] ^ -variances.scala:63: error: covariant type A occurs in contravariant position in type => test.Covariant.T[A]{val m: (A) => A} of value x +variances.scala:63: error: covariant type A occurs in contravariant position in type => test.Covariant.T[A]{val m: A => A} of value x val x: T[A] { ^ variances.scala:79: error: covariant type T occurs in contravariant position in type => test.TestAlias.B[C.this.A] of method foo diff --git a/test/files/pos/bug1439.flags b/test/files/pos/bug1439.flags new file mode 100644 index 0000000000..779916d58f --- /dev/null +++ b/test/files/pos/bug1439.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings \ No newline at end of file diff --git a/test/files/pos/bug1439.scala b/test/files/pos/bug1439.scala new file mode 100644 index 0000000000..68a7332b2a --- /dev/null +++ b/test/files/pos/bug1439.scala @@ -0,0 +1,8 @@ +// no unchecked warnings +class View[C[A]] { } + +object Test { + null match { + case v: View[_] => + } +} diff --git a/test/files/pos/bug2094.scala b/test/files/pos/bug2094.scala new file mode 100644 index 0000000000..ff142117b2 --- /dev/null +++ b/test/files/pos/bug2094.scala @@ -0,0 +1,31 @@ +object Test extends App { + // compiles: + Map[Int, Value]( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // does not compile: + Map( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // Experiment.scala:10: error: type mismatch; + // found : (Int, KnownType) + // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 + // 0 -> KnownType(classOf[Object]), + // ^ + // one error found +} +sealed trait Value { + def getType: Option[Class[_]] +} + +case class UnknownValue() extends Value { + def getType = None + // compiles if changed to: + // def getType: Option[Class[_]] = None +} + +case class KnownType(typ: Class[_]) extends Value { + def getType = Some(typ) +} \ No newline at end of file diff --git a/test/files/pos/bug3048.scala b/test/files/pos/bug3048.scala new file mode 100644 index 0000000000..dc056ecba2 --- /dev/null +++ b/test/files/pos/bug3048.scala @@ -0,0 +1,8 @@ +class B +object C extends B + +class F[T <: B](cons: => T) +class F2[T <: B](cons: => T) extends F(cons) + +object D extends F2(C) // works +object E extends F2(new B {}) diff --git a/test/files/pos/bug3343.scala b/test/files/pos/bug3343.scala new file mode 100644 index 0000000000..6c34cdff00 --- /dev/null +++ b/test/files/pos/bug3343.scala @@ -0,0 +1,15 @@ +import scala.collection.mutable.{ Builder, ListBuffer } + +object Test { + class Converter[T] + object SimpleIntConverter extends Converter[Int] + + class TraversableConverter[T, Coll[X] <: Traversable[X]](converter: Converter[T], builder: Builder[T, Coll[T]]) extends Converter[Coll[T]] { + def convert(x: T): List[T] = List(x) + } + val tc: Converter[List[Int]] = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int]) + val tc2 = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int]) + + def main(args: Array[String]): Unit = { + } +} \ No newline at end of file diff --git a/test/files/pos/bug3528.scala b/test/files/pos/bug3528.scala new file mode 100644 index 0000000000..ff49b3e929 --- /dev/null +++ b/test/files/pos/bug3528.scala @@ -0,0 +1,8 @@ +class A { + // 3528 - not fixed + // def f1 = List(List(1), Stream(1)) + // 3528 comments + def f2 = List(Set(1,2,3), List(1,2,3)) + // 2322 + def f3 = List(null: Range, null: List[Int]) +} diff --git a/test/files/pos/bug4018.scala b/test/files/pos/bug4018.scala new file mode 100644 index 0000000000..2b265c5717 --- /dev/null +++ b/test/files/pos/bug4018.scala @@ -0,0 +1,15 @@ +trait M[V[_]] + +class Cls[V[_]](c: M[V]) + +object Cls{ + def apply[V[_]](c: M[V]): Cls[V] = new Cls[V](c) +} + +object test { + val c: M[Option] = new M[Option] {} + new Cls(c) // does not infer. + new Cls[Option](c) // okay + Cls(c) // okay +} + diff --git a/test/files/pos/bug4237.scala b/test/files/pos/bug4237.scala new file mode 100644 index 0000000000..fcf6eb8bf1 --- /dev/null +++ b/test/files/pos/bug4237.scala @@ -0,0 +1,6 @@ +class A { + (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected + (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter + (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter + (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE +} \ No newline at end of file diff --git a/test/files/pos/bug4501.scala b/test/files/pos/bug4501.scala new file mode 100644 index 0000000000..40628f1a4b --- /dev/null +++ b/test/files/pos/bug4501.scala @@ -0,0 +1,14 @@ +// After lub modification +import scala.collection.mutable.ListBuffer + +class A { + def foo[T](a:T, b:T):T = a + def f1 = foo(ListBuffer(), List()) + def f2 = foo(ListBuffer(), ListBuffer()) + def f3 = foo(List(), List()) + + // scalap + // def f1 : scala.collection.Seq[scala.Nothing] = { /* compiled code */ } + // def f2 : scala.collection.mutable.ListBuffer[scala.Nothing] = { /* compiled code */ } + // def f3 : scala.collection.immutable.List[scala.Nothing] = { /* compiled code */ } +} \ No newline at end of file diff --git a/test/files/pos/bug4553.scala b/test/files/pos/bug4553.scala new file mode 100755 index 0000000000..4eefe57b2b --- /dev/null +++ b/test/files/pos/bug4553.scala @@ -0,0 +1,11 @@ +trait VectorLike[+T, +V[A] <: Vector[A]] { + def +[S, VResult[S] >: V[S]](v: VResult[S]) +} + +trait Vector[+T] extends VectorLike[T, Vector] +trait ImmutableVector[T] extends Vector[T] with VectorLike[T, ImmutableVector] +trait MutableVector[T] extends Vector[T] with VectorLike[T, MutableVector] + +object Test { + def f = (null: MutableVector[Int]) + (null: ImmutableVector[Int]) +} diff --git a/test/files/pos/bug4731.scala b/test/files/pos/bug4731.scala new file mode 100644 index 0000000000..d457543c1f --- /dev/null +++ b/test/files/pos/bug4731.scala @@ -0,0 +1,14 @@ +import java.util.Comparator + +trait Trait1[T] { def foo(arg: Comparator[T]): Unit } + +trait Trait2[T] extends Trait1[T] { def foo(arg: Comparator[String]): Int = 0 } + +class Class1 extends Trait2[String] { } + +object Test { + def main(args: Array[String]): Unit = { + val c = new Class1 + c.foo(Ordering[String]) + } +} diff --git a/test/files/pos/hk-infer.scala b/test/files/pos/hk-infer.scala new file mode 100644 index 0000000000..30e3476404 --- /dev/null +++ b/test/files/pos/hk-infer.scala @@ -0,0 +1,37 @@ +object Basis { + final case class X[T](t: T) + val x = Seq(X(32)) + val y = Seq(X(true)) + val x1 = Seq(X("asdf")) + val x2 = Seq(X('d')) +} +import Basis._ + +object DoesWork { + // Doesn'tWork + // def f1 = x ++ y ++ x1 ++ x2 + + def f2 = List(x, y, x1, x2).flatten +} + +// Testing the not giving of explicit Booper[M] arguments. +object ShouldWorkHK { + class Booper[M[_]](xs: Seq[M[_]]) extends collection.generic.SeqForwarder[M[_]] { + def underlying = xs + def BOOP(ys: Seq[M[_]]) = new Booper(xs ++ ys) + } + implicit def mkBoop[M[_]](xs: Seq[M[_]]) = new Booper(xs) + + def f1 = x BOOP y BOOP x1 BOOP x2 +} + +object DoesWorkHK { + class Booper[M[_]](xs: Seq[M[_]]) extends collection.generic.SeqForwarder[M[_]] { + def underlying = xs + def BOOP(ys: Seq[M[_]]) = new Booper[M](xs ++ ys) + } + implicit def mkBoop[M[_]](xs: Seq[M[_]]) = new Booper[M](xs) + + def f1 = x BOOP y BOOP x1 BOOP x2 +} + diff --git a/test/files/pos/no-widen-locals.scala b/test/files/pos/no-widen-locals.scala deleted file mode 100644 index 32579404b2..0000000000 --- a/test/files/pos/no-widen-locals.scala +++ /dev/null @@ -1,17 +0,0 @@ -import annotation.switch - -object Test { - def f(x: Int) = { - val X1 = 5 - val X2 = 10 - val X3 = 15 - val X4 = 20 - - (x: @switch) match { - case X1 => 1 - case X2 => 2 - case X3 => 3 - case X4 => 4 - } - } -} diff --git a/test/files/pos/spec-List.scala b/test/files/pos/spec-List.scala deleted file mode 100644 index 04ab7d1543..0000000000 --- a/test/files/pos/spec-List.scala +++ /dev/null @@ -1,869 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - -package scala.collection -package immutable - -import generic._ -import mutable.{Builder, ListBuffer} -import annotation.tailrec - -/** A class representing an ordered collection of elements of type - * a. This class comes with two implementing case - * classes scala.Nil and scala.:: that - * implement the abstract members isEmpty, - * head and tail. - * - * @author Martin Odersky and others - * @version 2.8 - */ -sealed trait List[@specialized +A] extends LinearSeq[A] - with Product - with GenericTraversableTemplate[A, List] - with LinearSeqOptimized[A, List[A]] { - override def companion: GenericCompanion[List] = List - - import scala.collection.{Iterable, Traversable, Seq} - - /** Returns true if the list does not contain any elements. - * @return true, iff the list is empty. - */ - def isEmpty: Boolean - - /** Returns this first element of the list. - * - * @return the first element of this list. - * @throws Predef.NoSuchElementException if the list is empty. - */ - def head: A - - /** Returns this list without its first element. - * - * @return this list without its first element. - * @throws Predef.NoSuchElementException if the list is empty. - */ - def tail: List[A] - - // New methods in List - - /**

- * Add an element x at the beginning of this list. - *

- * - * @param x the element to prepend. - * @return the list with x added at the beginning. - * @ex 1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3) - */ - def ::[@specialized B >: A] (x: B): List[B] = - new scala.collection.immutable.::(x, this) - - /**

- * Returns a list resulting from the concatenation of the given - * list prefix and this list. - *

- * - * @param prefix the list to concatenate at the beginning of this list. - * @return the concatenation of the two lists. - * @ex List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4) - */ - def :::[B >: A](prefix: List[B]): List[B] = - if (isEmpty) prefix - else (new ListBuffer[B] ++= prefix).prependToList(this) - - /** Reverse the given prefix and append the current list to that. - * This function is equivalent to an application of reverse - * on the prefix followed by a call to :::, but is more - * efficient. - * - * @param prefix the prefix to reverse and then prepend - * @return the concatenation of the reversed prefix and the current list. - */ - def reverse_:::[B >: A](prefix: List[B]): List[B] = { - var these: List[B] = this - var pres = prefix - while (!pres.isEmpty) { - these = pres.head :: these - pres = pres.tail - } - these - } - - /** Apply a function to all the elements of the list, and return the - * reversed list of results. This is equivalent to a call to map - * followed by a call to reverse, but more efficient. - * !!! should we deprecate this? Why have reverseMap, but not filterMap or reverseFilter, say? - * @param f the function to apply to each elements. - * @return the reversed list of results. - */ - def reverseMap[B](f: A => B): List[B] = { - @tailrec - def loop(l: List[A], res: List[B]): List[B] = l match { - case Nil => res - case head :: tail => loop(tail, f(head) :: res) - } - loop(this, Nil) - } - - /** Like xs map f, but returns xs unchanged if function - * f maps all elements to themselves (wrt ==). - * @note Unlike `map`, `mapConserve` is not tail-recursive. - */ - def mapConserve[B >: A] (f: A => B): List[B] = { - def loop(ys: List[A]): List[B] = - if (ys.isEmpty) this - else { - val head0 = ys.head - val head1 = f(head0) - if (head1 == head0) { - loop(ys.tail) - } else { - val ys1 = head1 :: ys.tail.mapConserve(f) - if (this eq ys) ys1 - else { - val b = new ListBuffer[B] - var xc = this - while (xc ne ys) { - b += xc.head - xc = xc.tail - } - b.prependToList(ys1) - } - } - } - loop(this) - } - - // Overridden methods from IterableLike or overloaded variants of such methods - - /** Create a new list which contains all elements of this list - * followed by all elements of Traversable `that' - */ - override def ++[B >: A, That](xs: GenTraversableOnce[B])(implicit bf: CanBuildFrom[List[A], B, That]): That = { - val b = bf(this) - if (b.isInstanceOf[ListBuffer[_]]) (this ::: xs.toList).asInstanceOf[That] - else super.++(xs) - } - - /** Overrides the method in Iterable for efficiency. - * - * @return the list itself - */ - override def toList: List[A] = this - - /** Returns the n first elements of this list, or else the whole - * list, if it has less than n elements. - - * @param n the number of elements to take. - * @return the n first elements of this list. - */ - override def take(n: Int): List[A] = { - val b = new ListBuffer[A] - var i = 0 - var these = this - while (!these.isEmpty && i < n) { - i += 1 - b += these.head - these = these.tail - } - if (these.isEmpty) this - else b.toList - } - - /** Returns the list without its n first elements. - * If this list has less than n elements, the empty list is returned. - * - * @param n the number of elements to drop. - * @return the list without its n first elements. - */ - override def drop(n: Int): List[A] = { - var these = this - var count = n - while (!these.isEmpty && count > 0) { - these = these.tail - count -= 1 - } - these - } - - /** Returns the list with elements belonging to the given index range. - * - * @param start the start position of the list slice. - * @param end the end position (exclusive) of the list slice. - * @return the list with elements belonging to the given index range. - */ - override def slice(start: Int, end: Int): List[A] = { - var len = end - if (start > 0) len -= start - drop(start) take len - } - - /** Returns the rightmost n elements from this list. - * - * @param n the number of elements to take - * @return the suffix of length n of the list - */ - override def takeRight(n: Int): List[A] = { - @tailrec - def loop(lead: List[A], lag: List[A]): List[A] = lead match { - case Nil => lag - case _ :: tail => loop(tail, lag.tail) - } - loop(drop(n), this) - } - - // dropRight is inherited from Stream - - /** Split the list at a given point and return the two parts thus - * created. - * - * @param n the position at which to split - * @return a pair of lists composed of the first n - * elements, and the other elements. - */ - override def splitAt(n: Int): (List[A], List[A]) = { - val b = new ListBuffer[A] - var i = 0 - var these = this - while (!these.isEmpty && i < n) { - i += 1 - b += these.head - these = these.tail - } - (b.toList, these) - } - - /** Returns the longest prefix of this list whose elements satisfy - * the predicate p. - * - * @param p the test predicate. - * @return the longest prefix of this list whose elements satisfy - * the predicate p. - */ - override def takeWhile(p: A => Boolean): List[A] = { - val b = new ListBuffer[A] - var these = this - while (!these.isEmpty && p(these.head)) { - b += these.head - these = these.tail - } - b.toList - } - - /** Returns the longest suffix of this list whose first element - * does not satisfy the predicate p. - * - * @param p the test predicate. - * @return the longest suffix of the list whose first element - * does not satisfy the predicate p. - */ - override def dropWhile(p: A => Boolean): List[A] = { - @tailrec - def loop(xs: List[A]): List[A] = - if (xs.isEmpty || !p(xs.head)) xs - else loop(xs.tail) - - loop(this) - } - - /** Returns the longest prefix of the list whose elements all satisfy - * the given predicate, and the rest of the list. - * - * @param p the test predicate - * @return a pair consisting of the longest prefix of the list whose - * elements all satisfy p, and the rest of the list. - */ - override def span(p: A => Boolean): (List[A], List[A]) = { - val b = new ListBuffer[A] - var these = this - while (!these.isEmpty && p(these.head)) { - b += these.head - these = these.tail - } - (b.toList, these) - } - - /** A list consisting of all elements of this list in reverse order. - */ - override def reverse: List[A] = { - var result: List[A] = Nil - var these = this - while (!these.isEmpty) { - result = these.head :: result - these = these.tail - } - result - } - - override def stringPrefix = "List" - - override def toStream : Stream[A] = - if (isEmpty) Stream.Empty - else new Stream.Cons(head, tail.toStream) - - // !!! todo: work in patch - - /** Computes the difference between this list and the given list - * that. - * - * @param that the list of elements to remove from this list. - * @return this list without the elements of the given list - * that. - */ - @deprecated("use `diff' instead") - def -- [B >: A](that: List[B]): List[B] = { - val b = new ListBuffer[B] - var these = this - while (!these.isEmpty) { - if (!that.contains(these.head)) b += these.head - these = these.tail - } - b.toList - } - - /** Computes the difference between this list and the given object - * x. - * - * @param x the object to remove from this list. - * @return this list without occurrences of the given object - * x. - */ - @deprecated("use `diff' instead") - def - [B >: A](x: B): List[B] = { - val b = new ListBuffer[B] - var these = this - while (!these.isEmpty) { - if (these.head != x) b += these.head - these = these.tail - } - b.toList - } - - /**

- * Sort the list according to the comparison function - * <(e1: a, e2: a) => Boolean, - * which should be true iff e1 is smaller than - * e2. - * !!! todo: move sorting to IterableLike - *

- * - * @param lt the comparison function - * @return a list sorted according to the comparison function - * <(e1: a, e2: a) => Boolean. - * @ex
-   *    List("Steve", "Tom", "John", "Bob")
-   *      .sort((e1, e2) => (e1 compareTo e2) < 0) =
-   *    List("Bob", "John", "Steve", "Tom")
- */ - @deprecated("use `sortWith' instead") - def sort(lt : (A,A) => Boolean): List[A] = { - /** Merge two already-sorted lists */ - def merge(l1: List[A], l2: List[A]): List[A] = { - val res = new ListBuffer[A] - var left1 = l1 - var left2 = l2 - - while (!left1.isEmpty && !left2.isEmpty) { - if(lt(left1.head, left2.head)) { - res += left1.head - left1 = left1.tail - } else { - res += left2.head - left2 = left2.tail - } - } - - res ++= left1 - res ++= left2 - - res.toList - } - - /** Split a list into two lists of about the same size */ - def split(lst: List[A]) = { - val res1 = new ListBuffer[A] - val res2 = new ListBuffer[A] - var left = lst - - while (!left.isEmpty) { - res1 += left.head - left = left.tail - if (!left.isEmpty) { - res2 += left.head - left = left.tail - } - } - - (res1.toList, res2.toList) - } - - - /** Merge-sort the specified list */ - def ms(lst: List[A]): List[A] = - lst match { - case Nil => lst - case x :: Nil => lst - case x :: y :: Nil => - if (lt(x,y)) - lst - else - y :: x :: Nil - - case lst => - val (l1, l2) = split(lst) - val l1s = ms(l1) - val l2s = ms(l2) - merge(l1s, l2s) - } - - ms(this) - } - -} - -/** The empty list. - * - * @author Martin Odersky - * @version 1.0, 15/07/2003 - */ -@SerialVersionUID(0 - 8256821097970055419L) -case object Nil extends List[Nothing] { - override def isEmpty = true - override def head: Nothing = - throw new NoSuchElementException("head of empty list") - override def tail: List[Nothing] = - throw new NoSuchElementException("tail of empty list") - // Removal of equals method here might lead to an infinite recusion similar to IntMap.equals. - override def equals(that: Any) = that match { - case that1: Seq[_] => that1.isEmpty - case _ => false - } -} - -/** A non empty list characterized by a head and a tail. - * - * @author Martin Odersky - * @version 1.0, 15/07/2003 - */ -@SerialVersionUID(0L - 8476791151983527571L) -final case class ::[@specialized B](private var hd: B, private[scala] var tl: List[B]) extends List[B] { - override def head : B = hd - override def tail : List[B] = tl - override def isEmpty: Boolean = false - - import java.io._ - - private def writeObject(out: ObjectOutputStream) { - var xs: List[B] = this - while (!xs.isEmpty) { out.writeObject(xs.head); xs = xs.tail } - out.writeObject(ListSerializeEnd) - } - - private def readObject(in: ObjectInputStream) { - hd = in.readObject.asInstanceOf[B] - assert(hd != ListSerializeEnd) - var current: ::[B] = this - while (true) in.readObject match { - case ListSerializeEnd => - current.tl = Nil - return - case a : Any => - val list : ::[B] = new ::(a.asInstanceOf[B], Nil) - current.tl = list - current = list - } - } -} - -/** This object provides methods for creating specialized lists, and for - * transforming special kinds of lists (e.g. lists of lists). - * - * @author Martin Odersky - * @version 2.8 - */ -object List extends SeqFactory[List] { - - import collection.{Iterable, Seq} - - implicit def builderFactory[A]: CanBuildFrom[Coll, A, List[A]] = - new GenericCanBuildFrom[A] { - override def apply() = newBuilder[A] - } - def newBuilder[A]: Builder[A, List[A]] = new ListBuffer[A] - - override def empty[A]: List[A] = Nil - - override def apply[A](xs: A*): List[A] = xs.toList - - /** Create a sorted list with element values - * vn+1 = step(vn) - * where v0 = start - * and elements are in the range between start (inclusive) - * and end (exclusive) - * - * @param start the start value of the list - * @param end the end value of the list - * @param step the increment function of the list, which given vn, - * computes vn+1. Must be monotonically increasing - * or decreasing. - * @return the sorted list of all integers in range [start;end). - */ - @deprecated("use `iterate' instead") - def range(start: Int, end: Int, step: Int => Int): List[Int] = { - val up = step(start) > start - val down = step(start) < start - val b = new ListBuffer[Int] - var i = start - while ((!up || i < end) && (!down || i > end)) { - b += i - val next = step(i) - if (i == next) - throw new IllegalArgumentException("the step function did not make any progress on "+ i) - i = next - } - b.toList - } - - /** Create a list containing several copies of an element. - * - * @param n the length of the resulting list - * @param elem the element composing the resulting list - * @return a list composed of n elements all equal to elem - */ - @deprecated("use `fill' instead") - def make[A](n: Int, elem: A): List[A] = { - val b = new ListBuffer[A] - var i = 0 - while (i < n) { - b += elem - i += 1 - } - b.toList - } - - /** Concatenate all the elements of a given list of lists. - * - * @param xss the list of lists that are to be concatenated - * @return the concatenation of all the lists - */ - @deprecated("use `xss.flatten' instead") - def flatten[A](xss: List[List[A]]): List[A] = { - val b = new ListBuffer[A] - for (xs <- xss) { - var xc = xs - while (!xc.isEmpty) { - b += xc.head - xc = xc.tail - } - } - b.toList - } - - /** Transforms a list of pairs into a pair of lists. - * - * @param xs the list of pairs to unzip - * @return a pair of lists. - */ - @deprecated("use `xs.unzip' instead") - def unzip[A,B](xs: List[(A,B)]): (List[A], List[B]) = { - val b1 = new ListBuffer[A] - val b2 = new ListBuffer[B] - var xc = xs - while (!xc.isEmpty) { - b1 += xc.head._1 - b2 += xc.head._2 - xc = xc.tail - } - (b1.toList, b2.toList) - } - - /** Transforms an iterable of pairs into a pair of lists. - * - * @param xs the iterable of pairs to unzip - * @return a pair of lists. - */ - @deprecated("use `xs.unzip' instead") - def unzip[A,B](xs: Iterable[(A,B)]): (List[A], List[B]) = - xs.foldRight[(List[A], List[B])]((Nil, Nil)) { - case ((x, y), (xs, ys)) => (x :: xs, y :: ys) - } - - /** - * Returns the Left values in the given Iterable - * of Eithers. - */ - @deprecated("use `Either.lefts' instead") - def lefts[A, B](es: Iterable[Either[A, B]]) = - es.foldRight[List[A]](Nil)((e, as) => e match { - case Left(a) => a :: as - case Right(_) => as - }) - - /** - * Returns the Right values in the givenIterable of Eithers. - */ - @deprecated("use `Either.rights' instead") - def rights[A, B](es: Iterable[Either[A, B]]) = - es.foldRight[List[B]](Nil)((e, bs) => e match { - case Left(_) => bs - case Right(b) => b :: bs - }) - - /** Transforms an Iterable of Eithers into a pair of lists. - * - * @param xs the iterable of Eithers to separate - * @return a pair of lists. - */ - @deprecated("use `Either.separate' instead") - def separate[A,B](es: Iterable[Either[A,B]]): (List[A], List[B]) = - es.foldRight[(List[A], List[B])]((Nil, Nil)) { - case (Left(a), (lefts, rights)) => (a :: lefts, rights) - case (Right(b), (lefts, rights)) => (lefts, b :: rights) - } - - /** Converts an iterator to a list. - * - * @param it the iterator to convert - * @return a list that contains the elements returned by successive - * calls to it.next - */ - @deprecated("use `it.toList' instead") - def fromIterator[A](it: Iterator[A]): List[A] = it.toList - - /** Converts an array into a list. - * - * @param arr the array to convert - * @return a list that contains the same elements than arr - * in the same order - */ - @deprecated("use `array.toList' instead") - def fromArray[A](arr: Array[A]): List[A] = fromArray(arr, 0, arr.length) - - /** Converts a range of an array into a list. - * - * @param arr the array to convert - * @param start the first index to consider - * @param len the length of the range to convert - * @return a list that contains the same elements than arr - * in the same order - */ - @deprecated("use `array.view(start, end).toList' instead") - def fromArray[A](arr: Array[A], start: Int, len: Int): List[A] = { - var res: List[A] = Nil - var i = start + len - while (i > start) { - i -= 1 - res = arr(i) :: res - } - res - } - - /** Parses a string which contains substrings separated by a - * separator character and returns a list of all substrings. - * - * @param str the string to parse - * @param separator the separator character - * @return the list of substrings - */ - @deprecated("use `str.split(separator).toList' instead") - def fromString(str: String, separator: Char): List[String] = { - var words: List[String] = Nil - var pos = str.length() - while (pos > 0) { - val pos1 = str.lastIndexOf(separator, pos - 1) - if (pos1 + 1 < pos) - words = str.substring(pos1 + 1, pos) :: words - pos = pos1 - } - words - } - - /** Returns the given string as a list of characters. - * - * @param str the string to convert. - * @return the string as a list of characters. - */ - @deprecated("use `str.toList' instead") - def fromString(str: String): List[Char] = str.toList - - /** Returns the given list of characters as a string. - * - * @param xs the list to convert. - * @return the list in form of a string. - */ - @deprecated("use `xs.mkString' instead") - def toString(xs: List[Char]): String = { - val sb = new StringBuilder() - var xc = xs - while (!xc.isEmpty) { - sb.append(xc.head) - xc = xc.tail - } - sb.toString() - } - - /** Like xs map f, but returns xs unchanged if function - * f maps all elements to themselves. - */ - @deprecated("use `xs.mapConserve(f)' instead") - def mapConserve[A <: AnyRef](xs: List[A])(f: A => A): List[A] = { - def loop(ys: List[A]): List[A] = - if (ys.isEmpty) xs - else { - val head0 = ys.head - val head1 = f(head0) - if (head1 eq head0) { - loop(ys.tail) - } else { - val ys1 = head1 :: mapConserve(ys.tail)(f) - if (xs eq ys) ys1 - else { - val b = new ListBuffer[A] - var xc = xs - while (xc ne ys) { - b += xc.head - xc = xc.tail - } - b.prependToList(ys1) - } - } - } - loop(xs) - } - - /** Returns the list resulting from applying the given function f - * to corresponding elements of the argument lists. - * @param f function to apply to each pair of elements. - * @return [f(a0,b0), ..., f(an,bn)] if the lists are - * [a0, ..., ak], [b0, ..., bl] and - * n = min(k,l) - */ - @deprecated("use `(xs, ys).map(f)' instead") - def map2[A,B,C](xs: List[A], ys: List[B])(f: (A, B) => C): List[C] = { - val b = new ListBuffer[C] - var xc = xs - var yc = ys - while (!xc.isEmpty && !yc.isEmpty) { - b += f(xc.head, yc.head) - xc = xc.tail - yc = yc.tail - } - b.toList - } - - /** Returns the list resulting from applying the given function - * f to corresponding elements of the argument lists. - * - * @param f function to apply to each pair of elements. - * @return [f(a0,b0,c0), - * ..., f(an,bn,cn)] - * if the lists are [a0, ..., ak], - * [b0, ..., bl], - * [c0, ..., cm] and - * n = min(k,l,m) - */ - @deprecated("use `(xs, ys, zs).map(f)' instead") - def map3[A,B,C,D](xs: List[A], ys: List[B], zs: List[C])(f: (A, B, C) => D): List[D] = { - val b = new ListBuffer[D] - var xc = xs - var yc = ys - var zc = zs - while (!xc.isEmpty && !yc.isEmpty && !zc.isEmpty) { - b += f(xc.head, yc.head, zc.head) - xc = xc.tail - yc = yc.tail - zc = zc.tail - } - b.toList - } - - /** Tests whether the given predicate p holds - * for all corresponding elements of the argument lists. - * - * @param p function to apply to each pair of elements. - * @return (p(a0,b0) && - * ... && p(an,bn))] - * if the lists are [a0, ..., ak]; - * [b0, ..., bl] - * and n = min(k,l) - */ - @deprecated("use `(xs, ys).forall(f)' instead") - def forall2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = { - var xc = xs - var yc = ys - while (!xc.isEmpty && !yc.isEmpty) { - if (!f(xc.head, yc.head)) return false - xc = xc.tail - yc = yc.tail - } - true - } - - /** Tests whether the given predicate p holds - * for some corresponding elements of the argument lists. - * - * @param p function to apply to each pair of elements. - * @return n != 0 && (p(a0,b0) || - * ... || p(an,bn))] if the lists are - * [a0, ..., ak], - * [b0, ..., bl] and - * n = min(k,l) - */ - @deprecated("use `(xs, ys).exists(f)' instead") - def exists2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = { - var xc = xs - var yc = ys - while (!xc.isEmpty && !yc.isEmpty) { - if (f(xc.head, yc.head)) return true - xc = xc.tail - yc = yc.tail - } - false - } - - /** Transposes a list of lists. - * pre: All element lists have the same length. - * - * @param xss the list of lists - * @return the transposed list of lists - */ - @deprecated("use p`xss.transpose' instead") - def transpose[A](xss: List[List[A]]): List[List[A]] = { - val buf = new ListBuffer[List[A]] - var yss = xss - while (!yss.head.isEmpty) { - buf += (yss map (_.head)) - yss = (yss map (_.tail)) - } - buf.toList - } - - /** Lists with ordered elements are ordered - implicit def list2ordered[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = new Ordered[List[a]] { - def compare [b >: List[a] <% Ordered[b]](y: b): Int = y match { - case y1: List[a] => compareLists(x, y1); - case _ => -(y compare x) - } - private def compareLists(xs: List[a], ys: List[a]): Int = { - if (xs.isEmpty && ys.isEmpty) 0 - else if (xs.isEmpty) -1 - else if (ys.isEmpty) 1 - else { - val s = xs.head compare ys.head; - if (s != 0) s - else compareLists(xs.tail, ys.tail) - } - } - } - */ -} - -/** Only used for list serialization */ -@SerialVersionUID(0L - 8476791151975527571L) -private[scala] case object ListSerializeEnd - diff --git a/test/files/pos/t1439.scala b/test/files/pos/t1439.scala deleted file mode 100644 index ae1fdd10b5..0000000000 --- a/test/files/pos/t1439.scala +++ /dev/null @@ -1,7 +0,0 @@ -class View[C[A]] {} - -object Test { - null match { - case v: View[_] => - } -} diff --git a/test/files/pos/t2179.scala b/test/files/pos/t2179.scala new file mode 100755 index 0000000000..89e22b6e2a --- /dev/null +++ b/test/files/pos/t2179.scala @@ -0,0 +1,3 @@ +object Test { + (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) +} diff --git a/test/files/pos/t3774.scala b/test/files/pos/t3774.scala new file mode 100644 index 0000000000..2869925b01 --- /dev/null +++ b/test/files/pos/t3774.scala @@ -0,0 +1,5 @@ +// This used to hang the lub process. Now it rejects the file. This is still not correct, +// but we can solve this only after a redesign of lub a la dot. +object Hang { + Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) +} diff --git a/test/files/pos/t4547.scala b/test/files/pos/t4547.scala new file mode 100644 index 0000000000..01f229bbf6 --- /dev/null +++ b/test/files/pos/t4547.scala @@ -0,0 +1,4 @@ +object Main { + def g: BigInt = 5 + BigInt(4) // since we're looking for an implicit that converts an int into something that has a + method that takes a BigInt, BigInt should be in the implicit scope + def g2 = 5 + BigInt(4) +} \ No newline at end of file diff --git a/test/files/pos/t4593.scala b/test/files/pos/t4593.scala new file mode 100644 index 0000000000..250f68216a --- /dev/null +++ b/test/files/pos/t4593.scala @@ -0,0 +1,20 @@ +// ticket #4593 +trait A { + + class B + case object D extends B + + class C { + + var x: B = D + + def y = synchronized { + x match { + case D => {} + } + } + + } + +} + diff --git a/test/files/pos/t4692.scala b/test/files/pos/t4692.scala new file mode 100644 index 0000000000..409daf2257 --- /dev/null +++ b/test/files/pos/t4692.scala @@ -0,0 +1,27 @@ +class TypeAliasVsImplicitTest { + + class For[m[_], a](x: m[a]) { + def map[b](y: a => b): m[b] = throw new Error + } + implicit def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x) + + trait MyList[A] + + def foo(xs: MyList[Int]) = xs.map(x => x) // compiles fine. + + type MyListOfInt = MyList[Int] + def bar(xs: MyListOfInt) = xs.map(x => x) // doesn't compile: value map is not a member of TypeAliasVsImplicitTest.this.MyListOfInt +} + +// minimal case -- the bug was in type constructor inference where `xs.type` needed to be widened *and* dealiased +// in 2.8.1 implicit conversion search started with a widened type, so that combo never came up +// object Test { +// class For[m[_], a](x: m[a]) +// def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x) +// +// trait MyList[A] +// type MyListOfInt = MyList[Int] +// +// val xs: MyListOfInt = error("") +// toFor(xs : xs.type) +// } \ No newline at end of file diff --git a/test/files/pos/widen-existential.scala b/test/files/pos/widen-existential.scala new file mode 100644 index 0000000000..d7fa3cc1d8 --- /dev/null +++ b/test/files/pos/widen-existential.scala @@ -0,0 +1,7 @@ +class A { + { val x = classOf[List[_]] } + def f = { + val g = classOf[List[_]] + List(g, g) + } +} \ No newline at end of file diff --git a/test/files/run/TestFlatMap.scala b/test/files/run/TestFlatMap.scala new file mode 100644 index 0000000000..e6fb696aa2 --- /dev/null +++ b/test/files/run/TestFlatMap.scala @@ -0,0 +1,29 @@ +import scala.collection.parallel.{ ParMap => PMap } +import scala.collection.parallel.mutable.{ ParHashSet => PMHashSet, ParHashMap => PMHashMap, ParArray } +import scala.util.Random +import scala.collection.parallel.CompositeThrowable + +object Test { + + def main(args: Array[String]) { + val N = 1500 + val M = 1500 + var unmatchedLeft = new PMHashSet[Int] + var unmatchedRight = new PMHashSet[Int] + Range(0, N).foreach{ x => unmatchedLeft += x} + Range(0, M).foreach{ x => unmatchedRight += x} + + try { + val matches = unmatchedLeft.flatMap{ lind: Int => + val dists = unmatchedRight.seq.map{ rind: Int => + val dist = Random.nextInt + (rind, dist) + } + dists + } + } catch { + case c: CompositeThrowable => for (t <- c.throwables) println("\n%s\n%s".format(t, t.getStackTrace.mkString("\n"))) + } + } + +} diff --git a/test/files/run/bug2308a.check b/test/files/run/bug2308a.check new file mode 100644 index 0000000000..888240c702 --- /dev/null +++ b/test/files/run/bug2308a.check @@ -0,0 +1 @@ +interface Test$T diff --git a/test/files/run/bug2308a.scala b/test/files/run/bug2308a.scala new file mode 100644 index 0000000000..fff158c772 --- /dev/null +++ b/test/files/run/bug2308a.scala @@ -0,0 +1,7 @@ +object Test { + trait T[M[_]] + + def f1 = classOf[T[X] forSome { type X[_] } ] + + def main(args: Array[String]): Unit = println(f1) +} diff --git a/test/files/run/bug4110.check b/test/files/run/bug4110.check new file mode 100644 index 0000000000..8b005989de --- /dev/null +++ b/test/files/run/bug4110.check @@ -0,0 +1,2 @@ +Object with Test$A with Test$B +Object with Test$A with Test$B diff --git a/test/files/run/bug4110.scala b/test/files/run/bug4110.scala new file mode 100644 index 0000000000..a42646ce52 --- /dev/null +++ b/test/files/run/bug4110.scala @@ -0,0 +1,11 @@ +object Test extends App { + def inferredType[T : Manifest](v : T) = println(manifest[T]) + + trait A + trait B + + inferredType(new A with B) + + val name = new A with B + inferredType(name) +} \ No newline at end of file diff --git a/test/files/run/bug4570.check b/test/files/run/bug4570.check new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/test/files/run/bug4570.check @@ -0,0 +1 @@ +foo diff --git a/test/files/run/bug4570.scala b/test/files/run/bug4570.scala new file mode 100644 index 0000000000..5e1a20c52d --- /dev/null +++ b/test/files/run/bug4570.scala @@ -0,0 +1,8 @@ +object Test extends Enumeration { + val foo = Value + def bar = withName("foo") + + def main(args: Array[String]): Unit = { + values foreach println + } +} diff --git a/test/files/run/bug4656.check b/test/files/run/bug4656.check new file mode 100644 index 0000000000..15a62794a9 --- /dev/null +++ b/test/files/run/bug4656.check @@ -0,0 +1 @@ +List(1, 2, 3) diff --git a/test/files/run/bug4656.scala b/test/files/run/bug4656.scala new file mode 100644 index 0000000000..4f3d189c8f --- /dev/null +++ b/test/files/run/bug4656.scala @@ -0,0 +1,13 @@ +object Test { + def f = { + val buf = new collection.mutable.ListBuffer[Int] + buf ++= List(1, 2, 3) + val l = buf.toList + buf prependToList List(4, 5, 6) + l + } + + def main(args: Array[String]): Unit = { + println(f) + } +} diff --git a/test/files/run/bug4660.scala b/test/files/run/bug4660.scala new file mode 100644 index 0000000000..e57bb4bf25 --- /dev/null +++ b/test/files/run/bug4660.scala @@ -0,0 +1,11 @@ +object Test { + def main(args: Array[String]): Unit = { + val traversable = 1 to 20 map (_.toString) + def normalize(m: Map[Char, Traversable[String]]) = m.map { case (k,v) => (k, v.toList) } + + val groupedFromView = (traversable view).groupBy(_(0)) + val groupedFromStrict = traversable.groupBy(_(0)) + + assert(normalize(groupedFromView) == normalize(groupedFromStrict)) + } +} diff --git a/test/files/run/bug4697.check b/test/files/run/bug4697.check new file mode 100644 index 0000000000..b9d569380c --- /dev/null +++ b/test/files/run/bug4697.check @@ -0,0 +1 @@ +50005000 diff --git a/test/files/run/bug4697.scala b/test/files/run/bug4697.scala new file mode 100644 index 0000000000..95592172e0 --- /dev/null +++ b/test/files/run/bug4697.scala @@ -0,0 +1,8 @@ +object Test { + var st = Stream(0) + for (i <- 1 to 10000) st = i +: st + + def main(args: Array[String]): Unit = { + println(st.take(10000).sum) + } +} diff --git a/test/files/run/constrained-types.check b/test/files/run/constrained-types.check index 6919eca9bc..66580f063a 100644 --- a/test/files/run/constrained-types.check +++ b/test/files/run/constrained-types.check @@ -100,7 +100,7 @@ scala> def m = { val y : String @Annot(x) = x y } // x should not escape the local scope with a narrow type -m: String @Annot("three") +m: java.lang.String @Annot(x) forSome { val x: java.lang.String } scala> diff --git a/test/files/run/getClassTest.check b/test/files/run/getClassTest.check new file mode 100644 index 0000000000..94e86c3889 --- /dev/null +++ b/test/files/run/getClassTest.check @@ -0,0 +1,18 @@ +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class +f5: java.lang.Class +f0: T +f1: class java.lang.Object +f2: class java.lang.Object +f3: class AnyRefs$A +f4: class AnyRefs$B +f5: class java.lang.Object +f6: class java.lang.Object +f7: class AnyRefs$A +f8: class AnyRefs$B +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class diff --git a/test/files/run/getClassTest.scala b/test/files/run/getClassTest.scala new file mode 100644 index 0000000000..951cc8d931 --- /dev/null +++ b/test/files/run/getClassTest.scala @@ -0,0 +1,66 @@ +class AnyVals { + def f1 = (5: Any).getClass + def f2 = (5: AnyVal).getClass + def f3 = 5.getClass + def f4 = (5: java.lang.Integer).getClass + def f5 = (5.asInstanceOf[AnyRef]).getClass + + // scalap says: + // + // def f1 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f2 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f3 : java.lang.Class[scala.Int] = { /* compiled code */ } + // def f4 : java.lang.Class[?0] forSome {type ?0 <: java.lang.Integer} = { /* compiled code */ } + // def f5 : java.lang.Class[?0] forSome {type ?0 <: scala.AnyRef} = { /* compiled code */ } + // + // java generic signature says: + // + // f1: java.lang.Class + // f2: java.lang.Class + // f3: java.lang.Class + // f4: java.lang.Class + // f5: java.lang.Class +} + +class AnyRefs { + class A + class B extends A + + def f1 = (new B: Any).getClass().newInstance() + def f2 = (new B: AnyRef).getClass().newInstance() + def f3 = (new B: A).getClass().newInstance() + def f4 = (new B: B).getClass().newInstance() + + def f0[T >: B] = (new B: T).getClass().newInstance() + + def f5 = f0[Any] + def f6 = f0[AnyRef] + def f7 = f0[A] + def f8 = f0[B] +} + +class MoreAnyRefs { + trait A + trait B + + // don't leak anon/refinements + def f1 = (new A with B { }).getClass() + def f2 = (new B with A { }).getClass() + def f3 = (new { def bippy() = 5 }).getClass() + def f4 = (new A { def bippy() = 5 }).getClass() +} + +object Test { + def returnTypes[T: Manifest] = ( + manifest[T].erasure.getMethods.toList + filter (_.getName startsWith "f") + sortBy (_.getName) + map (m => m.getName + ": " + m.getGenericReturnType.toString) + ) + + def main(args: Array[String]): Unit = { + returnTypes[AnyVals] foreach println + returnTypes[AnyRefs] foreach println + returnTypes[MoreAnyRefs] foreach println + } +} diff --git a/test/files/run/null-and-intersect.check b/test/files/run/null-and-intersect.check new file mode 100644 index 0000000000..81890cfeff --- /dev/null +++ b/test/files/run/null-and-intersect.check @@ -0,0 +1,9 @@ +1 +2 +3 +4 +1 +2 +1 +2 +2 diff --git a/test/files/run/null-and-intersect.scala b/test/files/run/null-and-intersect.scala new file mode 100644 index 0000000000..7266dabe6d --- /dev/null +++ b/test/files/run/null-and-intersect.scala @@ -0,0 +1,34 @@ +object Test { + trait Immortal + class Bippy extends Immutable with Immortal + class Boppy extends Immutable + + def f[T](x: Traversable[T]) = x match { + case _: Map[_, _] => 3 + case _: Seq[_] => 2 + case _: Iterable[_] => 1 + case _ => 4 + } + def g(x: Bippy) = x match { + case _: Immutable with Immortal => 1 + case _ => 2 + } + def h(x: Immutable) = x match { + case _: Immortal => 1 + case _ => 2 + } + + def main(args: Array[String]): Unit = { + println(f(Set(1))) + println(f(Seq(1))) + println(f(Map(1 -> 2))) + println(f(null)) + + println(g(new Bippy)) + println(g(null)) + + println(h(new Bippy)) + println(h(new Boppy)) + println(h(null)) + } +} diff --git a/test/files/run/view-headoption.check b/test/files/run/view-headoption.check new file mode 100644 index 0000000000..5c98b54b46 --- /dev/null +++ b/test/files/run/view-headoption.check @@ -0,0 +1,28 @@ +fail +success +f1: Some(5) +fail +success +f2: 5 +fail +success +fail +fail +success +fail +fail +fail +success +f3: Some(5) +fail +success +fail +success +fail +fail +success +fail +fail +fail +success +f4: 5 diff --git a/test/files/run/view-headoption.scala b/test/files/run/view-headoption.scala new file mode 100644 index 0000000000..659c7e6b82 --- /dev/null +++ b/test/files/run/view-headoption.scala @@ -0,0 +1,18 @@ +object Test { + val failer = () => { println("fail") ; None } + val succeeder = () => { println("success") ; Some(5) } + val fs = List(failer, succeeder, failer, failer, succeeder, failer, failer, failer, succeeder) + + def f0 = fs.view flatMap (f => f()) + def f1 = f0.headOption + def f2 = f0.head + def f3 = f0.lastOption + def f4 = f0.last + + def main(args: Array[String]): Unit = { + println("f1: " + f1) + println("f2: " + f2) + println("f3: " + f3) + println("f4: " + f4) + } +} diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index 6a0e83a47d..56295f204c 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -130,6 +130,13 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { (t.size == (0 max x min r.size) && t.start == r.start && t.step == r.step) :| str(r)+" / "+str(t)+": "+x } + property("init") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => + (r.size == 0) || { + val t = r.init + (t.size + 1 == r.size) && (t.isEmpty || t.head == r.head) + } + } + property("takeWhile") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r)), arbInt.arbitrary) { (r, x) => val t = (if (r.step > 0) r takeWhile (_ <= x) else r takeWhile(_ >= x)) if (r.size == 0) { diff --git a/test/files/specialized/fft.check b/test/files/specialized/fft.check index 69a3a61f36..845729084d 100644 --- a/test/files/specialized/fft.check +++ b/test/files/specialized/fft.check @@ -1,4 +1,4 @@ Processing 65536 items Boxed doubles: 0 Boxed ints: 2 -Boxed longs: 1310921 +Boxed longs: 1245366 -- cgit v1.2.3