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/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 +++++++++ 19 files changed, 267 insertions(+), 1 deletion(-) 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/run') 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) + } +} -- cgit v1.2.3