diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-01 07:45:41 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-01 08:29:16 -0700 |
commit | 835405ba4582b7d70e8bd31504d3d2ffaebe28a7 (patch) | |
tree | 9615846a0ec707e62884c600e5c1f823124221f5 /test/files/run | |
parent | c4e055c02125ebdcb91b7231f19995bb9dec0fd7 (diff) | |
parent | d5a5142b9858920cd9a5dbf0ca1ceebb8131aceb (diff) | |
download | scala-835405ba4582b7d70e8bd31504d3d2ffaebe28a7.tar.gz scala-835405ba4582b7d70e8bd31504d3d2ffaebe28a7.tar.bz2 scala-835405ba4582b7d70e8bd31504d3d2ffaebe28a7.zip |
Merge remote-tracking branch 'origin/2.10.x' into merge-210
# By Ruediger Klaehn (14) and others
# Via Josh Suereth (13) and others
* origin/2.10.x: (49 commits)
More useful -Xlog-implicits output.
Reflection tuning
Two more value classes.
Fixed cloning a double-linked list.
Expanded the reach of value classes.
Added/fixed test files for SI-6227
Two fixes for the worksheet instrumenter
Fix crasher from bug in maven ant tasks. Yippie.
Closes SI-6227
Fix for SI-6283, no abstract value classes.
hotfix for SI-6293
Commented out assertions
removes Symbol.kind and Type.kind
Add missing tests for SI-6190
SI-6281 macroArgs for defs with implicit args
SI-6280 Scaladoc: Reloading preserves anchors
Added test to ensure that ListMap.tail is O(1)
Made ListMap.tail O(1) instead of O(N)
SI-6052 - fix groupBy on parallel collections
SI-6272 Support lazy vals defined in try in template.
...
Diffstat (limited to 'test/files/run')
30 files changed, 532 insertions, 98 deletions
diff --git a/test/files/run/classtags_core.check b/test/files/run/classtags_core.check index 2241108ba0..6519db2178 100644 --- a/test/files/run/classtags_core.check +++ b/test/files/run/classtags_core.check @@ -1,30 +1,30 @@ -true -ClassTag[byte] -true -ClassTag[short] -true -ClassTag[char] -true -ClassTag[int] -true -ClassTag[long] -true -ClassTag[float] -true -ClassTag[double] -true -ClassTag[boolean] -true -ClassTag[void] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class scala.runtime.Null$] -true -ClassTag[Nothing] +true
+ClassTag[byte]
+true
+ClassTag[short]
+true
+ClassTag[char]
+true
+ClassTag[int]
+true
+ClassTag[long]
+true
+ClassTag[float]
+true
+ClassTag[double]
+true
+ClassTag[boolean]
+true
+ClassTag[void]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class scala.runtime.Null$]
+true
+ClassTag[class scala.runtime.Nothing$]
diff --git a/test/files/run/existentials3-new.check b/test/files/run/existentials3-new.check index 0d6f694a68..a036d92a24 100644 --- a/test/files/run/existentials3-new.check +++ b/test/files/run/existentials3-new.check @@ -1,24 +1,24 @@ -Bar.type, t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton
-Bar, t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar}
+Bar.type, t=TypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton
+Bar, t=TypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar}
Test.ToS, t=RefinedType, s=f3
Test.ToS, t=RefinedType, s=f4
Test.ToS, t=RefinedType, s=f5
() => Test.ToS, t=TypeRef, s=class Function0
() => Test.ToS, t=TypeRef, s=class Function0
-$anon, t=AbstractTypeRef, s= <: B with Test.ToS
-$anon, t=AbstractTypeRef, s= <: B with A with Test.ToS
+$anon, t=TypeRef, s= <: B with Test.ToS
+$anon, t=TypeRef, s= <: B with A with Test.ToS
List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List
List[Seq[Int]], t=TypeRef, s=class List
List[Seq[U forSome { type U <: Int }]], t=TypeRef, s=class List
-Bar.type, t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton
-Bar, t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar}
+Bar.type, t=TypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton
+Bar, t=TypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar}
Test.ToS, t=RefinedType, s=g3
Test.ToS, t=RefinedType, s=g4
Test.ToS, t=RefinedType, s=g5
() => Test.ToS, t=TypeRef, s=class Function0
() => Test.ToS, t=TypeRef, s=class Function0
-$anon, t=AbstractTypeRef, s= <: B with Test.ToS
-$anon, t=AbstractTypeRef, s= <: B with A with Test.ToS
+$anon, t=TypeRef, s= <: B with Test.ToS
+$anon, t=TypeRef, s= <: B with A with Test.ToS
List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List
List[Seq[Int]], t=TypeRef, s=class List
List[Seq[U forSome { type U <: Int }]], t=TypeRef, s=class List
diff --git a/test/files/run/existentials3-new.scala b/test/files/run/existentials3-new.scala index 649fac8327..16735eab4f 100644 --- a/test/files/run/existentials3-new.scala +++ b/test/files/run/existentials3-new.scala @@ -35,7 +35,7 @@ object Test { def printTpe(t: Type) = { val s = if (t.typeSymbol.isFreeType) t.typeSymbol.typeSignature.toString else t.typeSymbol.toString - println("%s, t=%s, s=%s".format(t, t.kind, s)) + println("%s, t=%s, s=%s".format(t, t.asInstanceOf[Product].productPrefix, s)) } def m[T: TypeTag](x: T) = printTpe(typeOf[T]) def m2[T: AbsTypeTag](x: T) = printTpe(implicitly[AbsTypeTag[T]].tpe) diff --git a/test/files/run/inline-ex-handlers.check b/test/files/run/inline-ex-handlers.check index a4c9f215e8..2bc72893e7 100644 --- a/test/files/run/inline-ex-handlers.check +++ b/test/files/run/inline-ex-handlers.check @@ -61,22 +61,22 @@ > ? LOAD_LOCAL(variable monitor4) > 305 MONITOR_EXIT > ? JUMP 12 -550c557,563 +550c557 < ? THROW(Throwable) --- > ? JUMP 12 +556c563,570 +< ? THROW(Throwable) +--- +> ? STORE_LOCAL(value t) +> ? JUMP 13 > > 12: > ? LOAD_LOCAL(variable monitor3) > 304 MONITOR_EXIT > ? STORE_LOCAL(value t) > ? JUMP 13 -556c569,582 -< ? THROW(Throwable) ---- -> ? STORE_LOCAL(value t) -> ? JUMP 13 -> +571a586,597 > 13: > 310 LOAD_MODULE object Predef > 310 CALL_PRIMITIVE(StartConcat) @@ -88,6 +88,7 @@ > 310 CALL_PRIMITIVE(EndConcat) > 310 CALL_METHOD scala.Predef.println (dynamic) > 310 JUMP 2 +> 580c606 < catch (Throwable) in ArrayBuffer(7, 8, 9, 10) starting at: 6 --- @@ -110,12 +111,12 @@ > 81 LOAD_LOCAL(value e) > ? STORE_LOCAL(variable exc1) > ? JUMP 12 -668c700,714 +668c700,701 < 81 THROW(Exception) --- > ? STORE_LOCAL(variable exc1) > ? JUMP 12 -> +684a718,730 > 12: > 83 LOAD_MODULE object Predef > 83 CONSTANT("finally") @@ -128,6 +129,7 @@ > 84 STORE_LOCAL(variable result) > 84 LOAD_LOCAL(variable exc1) > 84 THROW(Throwable) +> 690c736 < catch (<none>) in ArrayBuffer(4, 6, 7, 9) starting at: 3 --- @@ -171,17 +173,18 @@ --- > ? STORE_LOCAL(value ex6) > ? JUMP 33 -802c854,861 +802c854,855 < 170 THROW(Throwable) --- > ? STORE_LOCAL(value ex6) > ? JUMP 33 -> +811a865,870 > 33: > 169 LOAD_LOCAL(value ex6) > 169 STORE_LOCAL(value x4) > 169 SCOPE_ENTER value x4 > 169 JUMP 5 +> 826,829d884 < 180 LOAD_LOCAL(value x5) < 180 CALL_METHOD MyException.message (dynamic) @@ -207,7 +210,7 @@ --- > ? STORE_LOCAL(variable exc2) > ? JUMP 34 -842a902,914 +857a917,929 > 34: > 184 LOAD_MODULE object Predef > 184 CONSTANT("finally") diff --git a/test/files/run/macro-expand-implicit-argument.check b/test/files/run/macro-expand-implicit-argument.check new file mode 100644 index 0000000000..fb42345748 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument.check @@ -0,0 +1 @@ +List(1, 2, 3)
diff --git a/test/files/run/macro-expand-implicit-argument.flags b/test/files/run/macro-expand-implicit-argument.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/run/macro-expand-implicit-argument/Macros_1.scala b/test/files/run/macro-expand-implicit-argument/Macros_1.scala new file mode 100644 index 0000000000..7629c5a9e2 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument/Macros_1.scala @@ -0,0 +1,59 @@ +import annotation.tailrec +import scala.math.{min, max} +import scala.{specialized => spec} + +import language.experimental.macros + +import scala.reflect.{ClassTag, TypeTag} +import scala.reflect.macros.Context + +object Macros { + def alloc[@spec A:ClassTag](src:Array[A], s1:Int, len:Int) = { + val as = Array.ofDim[A](len) + System.arraycopy(src, s1, as, 0, len) + as + } + + /** + * Efficient alternative to Array.apply. + * + * "As seen on scala-internals!" + */ + def array[A](as:A*)(implicit ct: ClassTag[A]) = macro arrayMacro[A] + + /** + * Takes in something like: + * ArrayUtil.alloc[Int](11, 22, 33, 44)(ct) + * + * and builds a tree like: + * { + * val arr:Array[Int] = ct.newArray(4) + * arr.update(0, 11) + * arr.update(1, 22) + * arr.update(2, 33) + * arr.update(3, 44) + * arr + * } + */ + def arrayMacro[A:c.AbsTypeTag](c:Context)(as:c.Expr[A]*)(ct: c.Expr[ClassTag[A]]): c.Expr[Array[A]] = { + import c.mirror._ + import c.universe._ + def const(x:Int) = Literal(Constant(x)) + + val n = as.length + val arr = newTermName("arr") + + val create = Apply(Select(ct.tree, "newArray"), List(const(n))) + val arrtpe = TypeTree(implicitly[c.AbsTypeTag[Array[A]]].tpe) + val valdef = ValDef(Modifiers(), arr, arrtpe, create) + + val updates = (0 until n).map { + i => Apply(Select(Ident(arr), "update"), List(const(i), as(i).tree)) + } + + val exprs = Seq(valdef) ++ updates ++ Seq(Ident(arr)) + val block = Block(exprs:_*) + + c.Expr[Array[A]](block) + } +}
\ No newline at end of file diff --git a/test/files/run/macro-expand-implicit-argument/Test_2.scala b/test/files/run/macro-expand-implicit-argument/Test_2.scala new file mode 100644 index 0000000000..ce8a068fb4 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + println(array(1, 2, 3).toList) +}
\ No newline at end of file diff --git a/test/files/run/partialfun.check b/test/files/run/partialfun.check new file mode 100644 index 0000000000..a317f7b150 --- /dev/null +++ b/test/files/run/partialfun.check @@ -0,0 +1,6 @@ +47
+147
+100
+0:isDefinedAt
+1:isDefinedAt
+2:apply
diff --git a/test/files/run/partialfun.scala b/test/files/run/partialfun.scala new file mode 100644 index 0000000000..4b360750c9 --- /dev/null +++ b/test/files/run/partialfun.scala @@ -0,0 +1,86 @@ +import collection._
+import collection.generic._
+
+object Test {
+ def collectIDA[A, B, Repr, That](_this: TraversableLike[A, Repr])(pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
+ val repr: Repr = _this.asInstanceOf[Repr]
+ val b = bf(repr)
+ _this foreach { x => if (pf isDefinedAt x) b += pf(x) }
+ b.result
+ }
+
+ def collectRW[A, B, Repr, That](_this: TraversableLike[A, Repr])(pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
+ val repr: Repr = _this.asInstanceOf[Repr]
+ val b = bf(repr)
+ val f = pf runWith { b += _ }
+ _this foreach f
+ b.result
+ }
+
+ var cnt = 0
+
+ object Ex1 {
+ def unapply(x: Int) : Option[Int] = {
+ cnt += 1
+ if ((x % 3) == 0) Some(-x) else None
+ }
+ }
+
+ object Ex2 {
+ def unapply(x: Int) : Option[Int] = {
+ //cnt += 1
+ if ((x % 5) == 0) Some(x) else None
+ }
+ }
+
+ def resetCnt() = { val r = cnt; cnt = 0; r }
+
+ val pf: PartialFunction[Int,Int] = {
+ case Ex1(result) => result
+ case Ex2(result) => result
+ }
+
+ def collectTest() {
+ val xs = 1 to 100
+ resetCnt()
+
+ val ysIDA = collectIDA(xs)(pf)
+ val cntIDA = resetCnt()
+
+ val ysRW = collectRW(xs)(pf)
+ val cntRW = resetCnt()
+
+ val ys = xs collect pf
+
+ assert(ys == ysIDA)
+ assert(ys == ysRW)
+ assert(cntIDA == xs.length + ys.length)
+ assert(cntRW == xs.length)
+ println(ys.length)
+ println(cntIDA)
+ println(cntRW)
+ }
+
+ def orElseTest() {
+ val pf0 = new PartialFunction[Unit, Unit] {
+ def apply(u: Unit) { println("0:apply") }
+ def isDefinedAt(u: Unit) = { println("0:isDefinedAt"); false }
+ }
+ val pf1 = new PartialFunction[Unit, Unit] {
+ def apply(u: Unit) { println("1:apply") }
+ def isDefinedAt(u: Unit) = { println("1:isDefinedAt"); false }
+ }
+ val pf2 = new PartialFunction[Unit, Unit] {
+ def apply(u: Unit) { println("2:apply") }
+ def isDefinedAt(u: Unit) = { println("2:isDefinedAt"); true }
+ }
+
+ val chained = pf0 orElse pf1 orElse pf2
+ chained()
+ }
+
+ def main(args: Array[String]): Unit = {
+ collectTest()
+ orElseTest()
+ }
+}
diff --git a/test/files/run/reflection-sorted-decls.check b/test/files/run/reflection-sorted-decls.check index 9a9832a683..02168c4e5f 100644 --- a/test/files/run/reflection-sorted-decls.check +++ b/test/files/run/reflection-sorted-decls.check @@ -1,7 +1,3 @@ value a
value b
value c
-method c
-method b
-method a
-constructor Foo$1
diff --git a/test/files/run/reflection-sorted-decls.scala b/test/files/run/reflection-sorted-decls.scala index 242f17d9bb..5616e10b3b 100644 --- a/test/files/run/reflection-sorted-decls.scala +++ b/test/files/run/reflection-sorted-decls.scala @@ -3,6 +3,6 @@ object Test { class Foo(val a: Int, val b: Int, val c: Int) import scala.reflect.runtime.{currentMirror => cm} val decls = cm.classSymbol(classOf[Foo]).typeSignature.declarations - decls.sorted.toList foreach System.out.println + decls.sorted.toList.filter(!_.isMethod) foreach System.out.println } } diff --git a/test/files/run/reflection-sorted-members.check b/test/files/run/reflection-sorted-members.check index d58b691c42..bb85b5a13c 100644 --- a/test/files/run/reflection-sorted-members.check +++ b/test/files/run/reflection-sorted-members.check @@ -1,34 +1,4 @@ value a
value b
value c
-method c
-method b
-method a
-constructor Foo$1
value x
-method x
-constructor Bar$1
-method finalize
-method wait
-method wait
-method wait
-method equals
-method toString
-method hashCode
-method getClass
-method clone
-method notify
-method notifyAll
-constructor Object
-method eq
-method ne
-method ==
-method !=
-method ##
-method synchronized
-method $isInstanceOf
-method $asInstanceOf
-method ==
-method !=
-method isInstanceOf
-method asInstanceOf
diff --git a/test/files/run/reflection-sorted-members.scala b/test/files/run/reflection-sorted-members.scala index 9980d79999..a8379234c0 100644 --- a/test/files/run/reflection-sorted-members.scala +++ b/test/files/run/reflection-sorted-members.scala @@ -6,6 +6,6 @@ object Test { class Foo(val a: Int, val b: Int, val c: Int) extends Bar(a + b + c) with T1 with T2 import scala.reflect.runtime.{currentMirror => cm} val members = cm.classSymbol(classOf[Foo]).typeSignature.members - members.sorted.toList foreach System.out.println + members.sorted.toList.filter(!_.isMethod) foreach System.out.println } } diff --git a/test/files/run/richWrapperEquals.scala b/test/files/run/richWrapperEquals.scala index 44beb133b3..4a43617cde 100644 --- a/test/files/run/richWrapperEquals.scala +++ b/test/files/run/richWrapperEquals.scala @@ -1,10 +1,6 @@ object Test { def main(args: Array[String]): Unit = { - assert(intWrapper(5) == 5) - assert(5 == intWrapper(5)) assert(5 == (5: java.lang.Integer)) assert((5: java.lang.Integer) == 5) - assert((5: java.lang.Integer) == intWrapper(5)) - assert(intWrapper(5) == (5: java.lang.Integer)) } } diff --git a/test/files/run/stream-stack-overflow-filter-map.scala b/test/files/run/stream-stack-overflow-filter-map.scala new file mode 100644 index 0000000000..f3a9dd49cb --- /dev/null +++ b/test/files/run/stream-stack-overflow-filter-map.scala @@ -0,0 +1,44 @@ +import collection.generic.{FilterMonadic, CanBuildFrom} + +object Test extends App { + def mapSucc[Repr, That](s: FilterMonadic[Int, Repr])(implicit cbf: CanBuildFrom[Repr, Int, That]) = s map (_ + 1) + def flatMapId[T, Repr, That](s: FilterMonadic[T, Repr])(implicit cbf: CanBuildFrom[Repr, T, That]) = s flatMap (Seq(_)) + + def testStreamPred(s: Stream[Int])(p: Int => Boolean) { + val res1 = s withFilter p + val res2 = s filter p + + val expected = s.toSeq filter p + + val fMapped1 = flatMapId(res1) + val fMapped2 = flatMapId(res2) + assert(fMapped1 == fMapped2) + assert(fMapped1.toSeq == expected) + + val mapped1 = mapSucc(res1) + val mapped2 = mapSucc(res2) + assert(mapped1 == mapped2) + assert(mapped1.toSeq == (expected map (_ + 1))) + + assert((res1 map identity).toSeq == res2.toSeq) + } + + def testStream(s: Stream[Int]) { + testStreamPred(s)(_ => false) + testStreamPred(s)(_ => true) + testStreamPred(s)(_ % 2 == 0) + testStreamPred(s)(_ % 3 == 0) + } + + //Reduced version of the test case - either invocation used to cause a stack + //overflow before commit 80b3f433e5536d086806fa108ccdfacf10719cc2. + val resFMap = (1 to 10000).toStream withFilter (_ => false) flatMap (Seq(_)) + val resMap = (1 to 10000).toStream withFilter (_ => false) map (_ + 1) + + //Complete test case for withFilter + map/flatMap, as requested by @axel22. + for (j <- (0 to 3) :+ 10000) { + val stream = (1 to j).toStream + assert(stream.toSeq == (1 to j).toSeq) + testStream(stream) + } +} diff --git a/test/files/run/t1987b.check b/test/files/run/t1987b.check new file mode 100644 index 0000000000..68d4b10e12 --- /dev/null +++ b/test/files/run/t1987b.check @@ -0,0 +1 @@ +ok! diff --git a/test/files/run/t1987b/PullIteratees.scala b/test/files/run/t1987b/PullIteratees.scala new file mode 100644 index 0000000000..a5a3e65d8f --- /dev/null +++ b/test/files/run/t1987b/PullIteratees.scala @@ -0,0 +1,17 @@ +package scales.xml + +trait PullType +class QName +trait RetUrn[T] + +/** + * Iteratees related to pull parsing + */ +trait PullIteratees { + /** + * Without the overload it doesn't trigger the CCE, even though its + * not used + */ + def iterate(path: List[QName], xml: String): RetUrn[String] = null + def iterate(path: List[QName], xml: Iterator[PullType]): RetUrn[String] = null +} diff --git a/test/files/run/t1987b/a.scala b/test/files/run/t1987b/a.scala new file mode 100644 index 0000000000..c1be5fe3e0 --- /dev/null +++ b/test/files/run/t1987b/a.scala @@ -0,0 +1,6 @@ +object Test { + def main(args: Array[String]): Unit = { + scales.xml.CCE_Test.main(args) + println("ok!") + } +} diff --git a/test/files/run/t1987b/cce_test.scala b/test/files/run/t1987b/cce_test.scala new file mode 100644 index 0000000000..4f9acf0264 --- /dev/null +++ b/test/files/run/t1987b/cce_test.scala @@ -0,0 +1,15 @@ +package scales.xml +//import scales.xml._ // using another pacakge and importing doesn't CCE + +object CCE_Test { + def main(args: Array[String]): Unit = { + // without the import it doesn't trigger the CCE + import scaley.funny._ + + val pull = null.asInstanceOf[Iterator[PullType]] + val LogEntries = null.asInstanceOf[List[QName]] + // fully qualify with scales.xml. and it won't trigger it + iterate(LogEntries, + pull) + } +} diff --git a/test/files/run/t1987b/pkg1.scala b/test/files/run/t1987b/pkg1.scala new file mode 100644 index 0000000000..6e749fc6b3 --- /dev/null +++ b/test/files/run/t1987b/pkg1.scala @@ -0,0 +1,4 @@ +package scaley + +package object funny { +} diff --git a/test/files/run/t1987b/pkg2.scala b/test/files/run/t1987b/pkg2.scala new file mode 100644 index 0000000000..38056a199e --- /dev/null +++ b/test/files/run/t1987b/pkg2.scala @@ -0,0 +1,3 @@ +package scales + +package object xml extends PullIteratees diff --git a/test/files/run/t5356.check b/test/files/run/t5356.check index 21c4aef07b..7522e7ea74 100644 --- a/test/files/run/t5356.check +++ b/test/files/run/t5356.check @@ -1,6 +1,6 @@ -1 scala.runtime.RichInt -1 scala.runtime.RichInt +1 java.lang.Integer +1 java.lang.Integer 1 scala.math.BigInt -1 scala.runtime.RichDouble -1 scala.runtime.RichFloat +1 java.lang.Double +1 java.lang.Float 1 diff --git a/test/files/run/t5356.scala b/test/files/run/t5356.scala index f7696c6088..ec17e036ad 100644 --- a/test/files/run/t5356.scala +++ b/test/files/run/t5356.scala @@ -1,12 +1,12 @@ object Test { - def f(x: { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName) - + def f(x: Any { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName) + def main(args: Array[String]): Unit = { f(1) f(1.toInt) f(BigInt(1)) f(1d) f(1f) - println((1: { def toInt: Int }).toInt) + println((1: (Any { def toInt: Int })).toInt) } } diff --git a/test/files/run/t6261.scala b/test/files/run/t6261.scala new file mode 100644 index 0000000000..b4463256c9 --- /dev/null +++ b/test/files/run/t6261.scala @@ -0,0 +1,130 @@ +import scala.collection.immutable._ + +object Test extends App { + + def test0() { + val m=ListMap(1->2,3->4) + if(m.tail ne m.tail) + println("ListMap.tail uses a builder, so it is not O(1)") + } + + def test1() { + // test that a HashTrieMap with one leaf element is not created! + val x = HashMap.empty + (1->1) + (2->2) + if(x.getClass.getSimpleName != "HashTrieMap") + println("A hash map containing two non-colliding values should be a HashTrieMap") + + val y = x - 1 + if(y.getClass.getSimpleName != "HashMap1") + println("A hash map containing one element should always use HashMap1") + } + + def test2() { + // class that always causes hash collisions + case class Collision(value:Int) { override def hashCode = 0 } + + // create a set that should have a collison + val x = HashMap.empty + (Collision(0)->0) + (Collision(1) ->0) + if(x.getClass.getSimpleName != "HashMapCollision1") + println("HashMap of size >1 with collisions should use HashMapCollision") + + // remove the collision again by removing all but one element + val y = x - Collision(0) + if(y.getClass.getSimpleName != "HashMap1") + println("HashMap of size 1 should use HashMap1" + y.getClass) + } + def test3() { + // finds an int x such that improved(x) differs in the first bit to improved(0), + // which is the worst case for the HashTrieSet + def findWorstCaseInts() { + // copy of improve from HashSet + def improve(hcode: Int) = { + var h: Int = hcode + ~(hcode << 9) + h = h ^ (h >>> 14) + h = h + (h << 4) + h ^ (h >>> 10) + } + + // find two hashes which have a large separation + val x = 0 + var y = 1 + val ix = improve(x) + while(y!=0 && improve(y)!=ix+(1<<31)) + y+=1 + printf("%s %s %x %x\n",x,y,improve(x), improve(y)) + } + // this is not done every test run since it would slow down ant test.suite too much. + // findWorstCaseInts() + + // two numbers that are immediately adiacent when fed through HashSet.improve + val h0 = 0 + val h1 = 1270889724 + + // h is the hashcode, i is ignored for the hashcode but relevant for equality + case class Collision(h:Int, i:Int) { + override def hashCode = h + } + val a = Collision(h0,0)->0 + val b = Collision(h0,1)->0 + val c = Collision(h1,0)->0 + + // create a HashSetCollision1 + val x = HashMap(a) + b + if(x.getClass.getSimpleName != "HashMapCollision1") + println("x should be a HashMapCollision") + StructureTests.validate(x) + //StructureTests.printStructure(x) + require(x.size==2 && x.contains(a._1) && x.contains(b._1)) + + // go from a HashSetCollision1 to a HashTrieSet with maximum depth + val y = x + c + if(y.getClass.getSimpleName != "HashTrieMap") + println("y should be a HashTrieMap") + StructureTests.validate(y) + // StructureTests.printStructure(y) + require(y.size==3 && y.contains(a._1) && y.contains(b._1) && y.contains(c._1)) + + // go from a HashSet1 directly to a HashTrieSet with maximum depth + val z = HashMap(a) + c + if(y.getClass.getSimpleName != "HashTrieMap") + println("y should be a HashTrieMap") + StructureTests.validate(z) + // StructureTests.printStructure(z) + require(z.size == 2 && z.contains(a._1) && z.contains(c._1)) + } + test0() + test1() + test2() + test3() +} + + +package scala.collection.immutable { + object StructureTests { + def printStructure(x:HashMap[_,_], prefix:String="") { + x match { + case m:HashMap.HashTrieMap[_,_] => + println(prefix+m.getClass.getSimpleName + " " + m.size) + m.elems.foreach(child => printStructure(child, prefix + " ")) + case m:HashMap.HashMapCollision1[_,_] => + println(prefix+m.getClass.getSimpleName + " " + m.kvs.size) + case m:HashMap.HashMap1[_,_] => + println(prefix+m.getClass.getSimpleName + " " + m.head) + case _ => + println(prefix+"empty") + } + } + + def validate(x:HashMap[_,_]) { + x match { + case m:HashMap.HashTrieMap[_,_] => + require(m.elems.size>1 || (m.elems.size==1 && m.elems(0).isInstanceOf[HashMap.HashTrieMap[_,_]])) + m.elems.foreach(validate _) + case m:HashMap.HashMapCollision1[_,_] => + require(m.kvs.size>1) + case m:HashMap.HashMap1[_,_] => + case _ => + } + } + } +} diff --git a/test/files/run/t6272.check b/test/files/run/t6272.check new file mode 100644 index 0000000000..f00c965d83 --- /dev/null +++ b/test/files/run/t6272.check @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/test/files/run/t6272.scala b/test/files/run/t6272.scala new file mode 100644 index 0000000000..174436919b --- /dev/null +++ b/test/files/run/t6272.scala @@ -0,0 +1,62 @@ +// x1, x2, and x3 resulted in: symbol variable bitmap$0 does not exist in A.<init> +object A { + + try { + lazy val x1 = 1 + println(x1) + sys.error("!") + } catch { + case _: Throwable => + lazy val x2 = 2 + println(x2) + } finally { + lazy val x3 = 3 + println(x3) + } + + if ("".isEmpty) { + lazy val x4 = 4 + println(x4) + } + + var b = true + while(b) { + lazy val x5 = 5 + println(x5) + b = false + } + + + def method { + try { + lazy val x6 = 6 + println(x6) + sys.error("!") + } catch { + case _: Throwable => + lazy val x7 = 7 + println(x7) + } finally { + lazy val x8 = 8 + println(x8) + } + + if ("".isEmpty) { + lazy val x9 = 9 + println(x9) + } + + var b = true + while(b) { + lazy val x10 = 10 + println(x10) + b = false + } + } +} + +object Test { + def main(args: Array[String]) { + A.method + } +} diff --git a/test/files/run/t6292.scala b/test/files/run/t6292.scala new file mode 100644 index 0000000000..51e31f95fc --- /dev/null +++ b/test/files/run/t6292.scala @@ -0,0 +1,18 @@ + import scala.collection.mutable.DoubleLinkedList + +object Test { + def main(args: Array[String]): Unit = { + cloneAndtest(DoubleLinkedList[Int]()) + cloneAndtest(DoubleLinkedList[Int](1)) + cloneAndtest(DoubleLinkedList[Int](1,2,3,4)) + } + + def cloneAndtest(l: DoubleLinkedList[Int]): Unit = + testSame(l, l.clone.asInstanceOf[DoubleLinkedList[Int]]) + + def testSame(one: DoubleLinkedList[Int], two: DoubleLinkedList[Int]): Unit = { + def msg = s" for ${one} and ${two} !" + assert(one.size == two.size, s"Cloned sizes are not the same $msg!") + assert(one == two, s"Cloned lists are not equal $msg") + } +} diff --git a/test/files/run/try-catch-unify.check b/test/files/run/try-catch-unify.check index b1de2bfa74..67a8c64a33 100644 --- a/test/files/run/try-catch-unify.check +++ b/test/files/run/try-catch-unify.check @@ -1,3 +1,4 @@ Failure(java.lang.NumberFormatException: For input string: "Hi") Success(5.0) O NOES +Failure(java.lang.NumberFormatException: For input string: "Hi") diff --git a/test/files/run/try-catch-unify.scala b/test/files/run/try-catch-unify.scala index 0d819ab957..8cb14d060e 100644 --- a/test/files/run/try-catch-unify.scala +++ b/test/files/run/try-catch-unify.scala @@ -11,5 +11,6 @@ object Test { } catch { case t => println(t.getMessage) } + println(nonFatalCatch withTry ("Hi".toDouble)) } } |