diff options
Diffstat (limited to 'test/files/run')
51 files changed, 722 insertions, 92 deletions
diff --git a/test/files/run/Predef.readLine.scala b/test/files/run/Predef.readLine.scala index 54809f8071..ce8565864a 100644 --- a/test/files/run/Predef.readLine.scala +++ b/test/files/run/Predef.readLine.scala @@ -1,5 +1,5 @@ import java.io.StringReader -import scala.io.ReadStdin.readLine +import scala.io.StdIn.readLine object Test extends App { Console.withIn(new StringReader("")) { diff --git a/test/files/run/bigDecimalTest.check b/test/files/run/bigDecimalTest.check index 6d11c23fcd..36db6aaafe 100644 --- a/test/files/run/bigDecimalTest.check +++ b/test/files/run/bigDecimalTest.check @@ -3,4 +3,4 @@ 0 0 0 -14 +15 diff --git a/test/files/run/constrained-types.check b/test/files/run/constrained-types.check index d965d8a2ff..9a106785a1 100644 --- a/test/files/run/constrained-types.check +++ b/test/files/run/constrained-types.check @@ -149,13 +149,3 @@ scala> val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message ^ scala> - -scala> class Where(condition: Boolean) extends annotation.Annotation -defined class Where - -scala> - -scala> val x : Int @Where(self > 0 && self < 100) = 3 -x: Int @Where(self.>(0).&&(self.<(100))) = 3 - -scala> diff --git a/test/files/run/constrained-types.scala b/test/files/run/constrained-types.scala index 91bd856d00..7ec8f93d38 100644 --- a/test/files/run/constrained-types.scala +++ b/test/files/run/constrained-types.scala @@ -72,16 +72,10 @@ object A { val x = "hello" : String @ rep } val y = a.x // should drop the annotation val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message - -class Where(condition: Boolean) extends annotation.Annotation - -val x : Int @Where(self > 0 && self < 100) = 3 - """ override def transformSettings(s: Settings): Settings = { s.Xexperimental.value = true - s.selfInAnnots.value = true s.deprecation.value = true // when running that compiler, give it a scala-library to the classpath s.classpath.value = sys.props("java.class.path") diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala index c3ace590ed..1d4891fd1f 100644 --- a/test/files/run/global-showdef.scala +++ b/test/files/run/global-showdef.scala @@ -54,7 +54,7 @@ object Bippy { val run = new compiler.Run() run.compileSources(List(src)) } - output.linesIterator.toList + output.lines.toList } def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name) def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name) diff --git a/test/files/run/idempotency-case-classes.scala b/test/files/run/idempotency-case-classes.scala index 81e119582b..4ad132174d 100644 --- a/test/files/run/idempotency-case-classes.scala +++ b/test/files/run/idempotency-case-classes.scala @@ -12,7 +12,7 @@ object Test extends App { val tb = cm.mkToolBox() val tcasee = tb.typecheck(casee.tree) println(tcasee) - val rtcasee = tb.resetAllAttrs(tcasee) + val rtcasee = tb.untypecheck(tcasee) try { println(tb.eval(rtcasee)) } catch { diff --git a/test/files/run/idempotency-extractors.scala b/test/files/run/idempotency-extractors.scala index b66b043be1..8c0a0b1106 100644 --- a/test/files/run/idempotency-extractors.scala +++ b/test/files/run/idempotency-extractors.scala @@ -12,7 +12,7 @@ object Test extends App { val tb = cm.mkToolBox() val textractor = tb.typecheck(extractor.tree) println(textractor) - val rtextractor = tb.resetAllAttrs(textractor) + val rtextractor = tb.untypecheck(textractor) try { println(tb.eval(rtextractor)) } catch { diff --git a/test/files/run/idempotency-labels.scala b/test/files/run/idempotency-labels.scala index f1a185d3d0..084c93d3c6 100644 --- a/test/files/run/idempotency-labels.scala +++ b/test/files/run/idempotency-labels.scala @@ -13,7 +13,7 @@ object Test extends App { val tb = cm.mkToolBox() val tlabel = tb.typecheck(label.tree) println(tlabel) - val rtlabel = tb.resetAllAttrs(tlabel) + val rtlabel = tb.untypecheck(tlabel) try { println(tb.eval(rtlabel)) } catch { diff --git a/test/files/run/idempotency-lazy-vals.scala b/test/files/run/idempotency-lazy-vals.scala index e763f2f3f4..9d677caeca 100644 --- a/test/files/run/idempotency-lazy-vals.scala +++ b/test/files/run/idempotency-lazy-vals.scala @@ -17,7 +17,7 @@ object Test extends App { val tb = cm.mkToolBox() val tlazee = tb.typecheck(lazee.tree) println(tlazee) - val rtlazee = tb.resetAllAttrs(tlazee) + val rtlazee = tb.untypecheck(tlazee) try { println(tb.eval(rtlazee)) } catch { diff --git a/test/files/run/idempotency-this.scala b/test/files/run/idempotency-this.scala index 2db1efd2d1..26917ab743 100644 --- a/test/files/run/idempotency-this.scala +++ b/test/files/run/idempotency-this.scala @@ -12,7 +12,7 @@ object Test extends App { val tthiss = tb.typecheck(thiss.tree) println(tthiss) println(showRaw(tthiss)) - val rtthiss = tb.resetAllAttrs(tthiss) + val rtthiss = tb.untypecheck(tthiss) try { println(tb.eval(rtthiss)) } catch { diff --git a/test/files/run/is-valid-num.scala b/test/files/run/is-valid-num.scala index d314015dd4..65e8ceeca6 100644 --- a/test/files/run/is-valid-num.scala +++ b/test/files/run/is-valid-num.scala @@ -19,25 +19,27 @@ object Test { assert(!x.isValidChar, x) assert(!x.isValidShort, x) assert(!x.isValidByte, x) -// assert(y.isWhole, y) + assert(y.isWhole, y) assert(!y.isValidShort, y) assert(y.isValidChar, y) assert(y.isValidInt, y) - assert(y.isValidFloat, y) - assert(y.isValidDouble, y) + assert(y.isDecimalFloat, y) + assert(y.isDecimalDouble, y) assert(y.isValidLong, y) assert(!y.isValidByte, y) -// assert(!y1.isWhole) + assert(!y1.isWhole) assert(!y1.isValidLong, y1) - assert(!y1.isValidFloat, y1) - assert(!y1.isValidDouble, y1) + assert(y1.isDecimalFloat, y1) + assert(y1.isDecimalDouble, y1) + assert(!y1.isExactFloat, y1) + assert(!y1.isExactDouble, y1) assert(!y1.isValidInt, y1) assert(!y1.isValidChar, y1) assert(!y1.isValidShort, y1) assert(!y1.isValidByte, y1) assert(!y2.isValidLong, y2) - assert(y2.isValidFloat, y2) - assert(y2.isValidDouble, y2) + assert(y2.isExactFloat, y2) + assert(y2.isExactDouble, y2) assert(!l1.isValidInt && (l1 - 1).isValidInt, l1) assert(!l2.isValidInt && (l2 + 1).isValidInt, l2) @@ -170,8 +172,8 @@ object Test { if (!d.isInfinity) { val bd = BigDecimal(new java.math.BigDecimal(d)) // assert(!bd.isWhole, bd) - assert(bd.isValidDouble, bd) - assert(bd.isValidFloat == isFloat, bd) + assert(bd.isExactDouble, bd) + assert(bd.isExactFloat == isFloat, bd) assert(!bd.isValidLong, bd) assert(!bd.isValidInt, bd) assert(!bd.isValidChar, bd) @@ -210,9 +212,9 @@ object Test { val isFloat = !bi.toFloat.isInfinity && bd.compare(BigDecimal(new java.math.BigDecimal(bi.toFloat))) == 0 val isDouble = !bi.toDouble.isInfinity && bd.compare(BigDecimal(new java.math.BigDecimal(bi.toDouble))) == 0 -// assert(bd.isWhole, bd) - assert(bd.isValidDouble == isDouble, bd) - assert(bd.isValidFloat == isFloat, bd) + assert(bd.isWhole, bd) + assert(bd.isBinaryDouble == isDouble, bd) + assert(bd.isBinaryFloat == isFloat, bd) assert(bd.isValidLong == isLong, bd) assert(bd.isValidInt == isInt, bd) assert(bd.isValidChar == isChar, bd) diff --git a/test/files/run/large_code.check b/test/files/run/large_code.check new file mode 100644 index 0000000000..6ad50967bc --- /dev/null +++ b/test/files/run/large_code.check @@ -0,0 +1,3 @@ +newSource1.scala:1: error: Could not write class BigEnoughToFail because it exceeds JVM code size limits. Method tooLong's code too large! +class BigEnoughToFail { + ^ diff --git a/test/files/run/large_code.scala b/test/files/run/large_code.scala new file mode 100644 index 0000000000..f9d7f8c95b --- /dev/null +++ b/test/files/run/large_code.scala @@ -0,0 +1,24 @@ +import scala.tools.partest._ +import java.io.{Console => _, _} + +// a cold run of partest takes about 15s for this test on my laptop +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp -d " + testOutput.path + + // test that we hit the code size limit and error out gracefully + // 5958 is the magic number (2^16/11 -- each `a(1,2,3,4,5,6)` is 11 bytes of bytecode) + override def code + = s""" + |class BigEnoughToFail { + | def a(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Unit = {} + | def tooLong: Unit = { + | ${(1 to 5958) map (_ => "a(1,2,3,4,5,6)") mkString(";")} + | } + |}""".stripMargin.trim + + override def show(): Unit = { + Console.withErr(System.out) { + compile() + } + } +} diff --git a/test/files/run/macro-abort-fresh.check b/test/files/run/macro-abort-fresh.check index 9fddee57d4..5064b96eef 100644 --- a/test/files/run/macro-abort-fresh.check +++ b/test/files/run/macro-abort-fresh.check @@ -1,6 +1,6 @@ -fresh$1 -qwe1 -qwe2 +fresh$macro$1 +qwe$macro$2 +qwe$macro$3 reflective compilation has failed: blargh diff --git a/test/files/run/numbereq.scala b/test/files/run/numbereq.scala index d50db6d049..7ce4b23cf8 100644 --- a/test/files/run/numbereq.scala +++ b/test/files/run/numbereq.scala @@ -31,6 +31,24 @@ object Test { ).flatten } + // Don't necessarily expect BigDecimal created from BigInt to agree with Double here. + def isIffy(x: Any, y: Any, canSwap: Boolean = true): Boolean = x match { + case bd: BigDecimal => y match { + case _: Float | _: Double => bd.toString.length > 15 + case _ => false + } + case _ => canSwap && isIffy(y, x, false) + } + + // Don't necessarily expect BigInt to agree with Float/Double beyond a Long + def isIffyB(x: Any, y: Any, canSwap: Boolean = true): Boolean = x match { + case bi: BigInt => y match { + case _: Float | _: Double => bi < Long.MinValue || bi > Long.MaxValue + case _ => false + } + case _ => canSwap && isIffyB(y, x, false) + } + def main(args: Array[String]): Unit = { val ints = (0 to 15).toList map (Short.MinValue >> _) val ints2 = ints map (x => -x) @@ -46,7 +64,6 @@ object Test { val sets = setneg1 ++ setneg2 ++ List(zero) ++ setpos1 ++ setpos2 for (set <- sets ; x <- set ; y <- set) { - // println("'%s' == '%s' (%s == %s) (%s == %s)".format(x, y, x.hashCode, y.hashCode, x.##, y.##)) assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) assert(x.## == y.##, "%s != %s".format(x.getClass, y.getClass)) } @@ -64,9 +81,11 @@ object Test { val sets2 = setneg1 ++ setneg1b ++ setneg2 ++ setneg2b ++ List(zero) ++ setpos1 ++ setpos1b ++ setpos2 ++ setpos2b for (set <- sets2 ; x <- set ; y <- set) { -// println("'%s' == '%s' (%s == %s) (%s == %s)".format(x, y, x.hashCode, y.hashCode, x.##, y.##)) - assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) -// assert(x.## == y.##, "%s != %s".format(x.getClass, y.getClass)) Disable until Double.## is fixed (SI-5640) + if (!isIffy(x,y)) { + assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) + // The following is blocked by SI-8150 + // if (!isIffyB(x,y)) assert(x.## == y.##, "%x/%s != %x/%s from %s.## and %s.##".format(x.##, x.getClass, y.##, y.getClass, x, y)) + } } } } diff --git a/test/files/run/partialfun.scala b/test/files/run/partialfun.scala index f3c53b94ae..71c7d3e61c 100644 --- a/test/files/run/partialfun.scala +++ b/test/files/run/partialfun.scala @@ -76,7 +76,7 @@ object Test { } val chained = pf0 orElse pf1 orElse pf2 - chained() + chained(()) } def main(args: Array[String]): Unit = { diff --git a/test/files/run/private-override.scala b/test/files/run/private-override.scala deleted file mode 100644 index 0a3f57f97c..0000000000 --- a/test/files/run/private-override.scala +++ /dev/null @@ -1,17 +0,0 @@ -package test.p1.p2 { - abstract class A { - private[p2] def f2(): Int = 1 - } - abstract class Other extends A { - // It's a private method - not a private[p2] method. Not a failed - // "weaker access privileges" override, a different namespace. - private def f2(): Int = super.f2() + 2 - def go() = f2() - } -} - -object Test extends test.p1.p2.Other { - def main(args: Array[String]): Unit = { - println(go()) - } -} diff --git a/test/files/run/reify_ann3.check b/test/files/run/reify_ann3.check index d4cf660758..4f1c61cf0e 100644 --- a/test/files/run/reify_ann3.check +++ b/test/files/run/reify_ann3.check @@ -1,5 +1,5 @@ { - class Tree[A, B] extends AnyRef { + class Tree[A, +B] extends AnyRef { @new inline @getter() final <paramaccessor> val key: A = _; def <init>(key: A) = { super.<init>(); @@ -9,7 +9,7 @@ () } { - class Tree[A, B] extends AnyRef { + class Tree[A, +B] extends AnyRef { final <paramaccessor> private[this] val key: A = _; @inline @scala.annotation.meta.getter final <stable> <accessor> <paramaccessor> def key: A = Tree.this.key; def <init>(key: A): Tree[A,B] = { diff --git a/test/files/run/resetattrs-this.scala b/test/files/run/resetattrs-this.scala index 6150a4e265..ff45d61dfe 100644 --- a/test/files/run/resetattrs-this.scala +++ b/test/files/run/resetattrs-this.scala @@ -6,6 +6,6 @@ object Test extends App { val tb = cm.mkToolBox() val tree = Select(This(cm.staticPackage("scala").moduleClass), TermName("Predef")) val ttree = tb.typecheck(tree) - val rttree = tb.resetAllAttrs(ttree) + val rttree = tb.untypecheck(ttree) println(tb.eval(rttree) == Predef) } diff --git a/test/files/run/t5256h.check b/test/files/run/t5256h.check index 1a4a92a684..dc3e919897 100644 --- a/test/files/run/t5256h.check +++ b/test/files/run/t5256h.check @@ -3,5 +3,5 @@ Test.$anon$1 java.lang.Object { final private val x: Int def x(): Int - def <init>(): java.lang.Object{def x(): Int} + def <init>(): $anon$1 } diff --git a/test/files/run/t5629b.check b/test/files/run/t5629b.check index 1bc0248c3d..e0f25f0b05 100644 --- a/test/files/run/t5629b.check +++ b/test/files/run/t5629b.check @@ -2,7 +2,7 @@ MySmartPF.apply entered... newPF.applyOrElse entered... default -scala.MatchError: () (of class scala.runtime.BoxedUnit) +scala.MatchError: 1 (of class java.lang.Integer) === pf(42): MySmartPF.apply entered... newPF.applyOrElse entered... diff --git a/test/files/run/t5629b.scala b/test/files/run/t5629b.scala index 9ff29c8d89..5d402201ae 100644 --- a/test/files/run/t5629b.scala +++ b/test/files/run/t5629b.scala @@ -1,8 +1,3 @@ - - - - - object Test extends App { trait MyPF[@specialized(Int) -A] extends (A => Unit) { @@ -16,7 +11,7 @@ object Test extends App { trait MySmartPF[@specialized(Int) -A] extends MyPF[A] { def apply(x: A): Unit = { println("MySmartPF.apply entered...") - applyOrElse(x, { _: Any => throw new MatchError }) + applyOrElse(x, { default: Any => throw new MatchError(default) }) } } diff --git a/test/files/run/t576.check b/test/files/run/t576.check index 8a1218a102..6458d5d743 100644 --- a/test/files/run/t576.check +++ b/test/files/run/t576.check @@ -1,3 +1,4 @@ +warning: there were 1 deprecation warning(s); re-run with -deprecation for details 1 2 3 diff --git a/test/files/run/t6187.check b/test/files/run/t6187.check index 97ee68271a..0180125809 100644 --- a/test/files/run/t6187.check +++ b/test/files/run/t6187.check @@ -7,7 +7,7 @@ import scala.reflect.macros.blackbox.Context scala> def macroImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[List[T]] = { val r = c.universe.reify { List(t.splice) } - c.Expr[List[T]]( c.resetLocalAttrs(r.tree) ) + c.Expr[List[T]]( c.untypecheck(r.tree) ) } macroImpl: [T](c: scala.reflect.macros.blackbox.Context)(t: c.Expr[T])(implicit evidence$1: c.WeakTypeTag[T])c.Expr[List[T]] diff --git a/test/files/run/t6187.scala b/test/files/run/t6187.scala index 7d84419b8a..7a39cfd9e7 100644 --- a/test/files/run/t6187.scala +++ b/test/files/run/t6187.scala @@ -5,7 +5,7 @@ object Test extends ReplTest { import scala.language.experimental.macros, scala.reflect.macros.blackbox.Context def macroImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[List[T]] = { val r = c.universe.reify { List(t.splice) } - c.Expr[List[T]]( c.resetLocalAttrs(r.tree) ) + c.Expr[List[T]]( c.untypecheck(r.tree) ) } def demo[T](t: T): List[T] = macro macroImpl[T] def m[T](t: T): List[List[T]] = diff --git a/test/files/run/t6196.scala b/test/files/run/t6196.scala new file mode 100644 index 0000000000..16c2c7409d --- /dev/null +++ b/test/files/run/t6196.scala @@ -0,0 +1,68 @@ +import scala.collection.immutable.HashSet + +object Test extends App { + + case class Collision(value: Int) extends Ordered[Collision] { + def compare(that:Collision) = value compare that.value + + override def hashCode = value / 5 + } + + def testCorrectness[T : Ordering](n: Int, mkKey: Int => T) { + val o = implicitly[Ordering[T]] + val s = HashSet.empty[T] ++ (0 until n).map(mkKey) + for (i <- 0 until n) { + val ki = mkKey(i) + val a = s.filter(o.lt(_,ki)) + val b = s.filterNot(o.lt(_,ki)) + require(a.size == i && (0 until i).forall(i => a.contains(mkKey(i)))) + require(b.size == n - i && (i until n).forall(i => b.contains(mkKey(i)))) + } + } + + // this tests the structural sharing of the new filter + // I could not come up with a simple test that tests structural sharing when only parts are reused, but + // at least this fails with the old and passes with the new implementation + def testSharing() { + val s = HashSet.empty[Int] ++ (0 until 100) + require(s.filter(_ => true) eq s) + require(s.filterNot(_ => false) eq s) + } + + // this tests that neither hashCode nor equals are called during filter + def testNoHashing() { + var hashCount = 0 + var equalsCount = 0 + case class HashCounter(value:Int) extends Ordered[HashCounter] { + def compare(that:HashCounter) = value compare that.value + + override def hashCode = { + hashCount += 1 + value + } + + override def equals(that:Any) = { + equalsCount += 1 + this match { + case HashCounter(value) => this.value == value + case _ => false + } + } + } + + val s = HashSet.empty[HashCounter] ++ (0 until 100).map(HashCounter) + val hashCount0 = hashCount + val equalsCount0 = equalsCount + val t = s.filter(_<HashCounter(50)) + require(hashCount == hashCount0) + require(equalsCount == equalsCount0) + } + + // this tests correctness of filter and filterNot for integer keys + testCorrectness[Int](100, identity _) + // this tests correctness of filter and filterNot for keys with lots of collisions + // this is necessary because usually collisions are rare so the collision-related code is not thoroughly tested + testCorrectness[Collision](100, Collision.apply _) + testSharing() + testNoHashing() +} diff --git a/test/files/run/t6200.scala b/test/files/run/t6200.scala new file mode 100644 index 0000000000..9a5d91e042 --- /dev/null +++ b/test/files/run/t6200.scala @@ -0,0 +1,68 @@ +import scala.collection.immutable.HashMap + +object Test extends App { + + case class Collision(value: Int) extends Ordered[Collision] { + def compare(that: Collision) = value compare that.value + + override def hashCode = value / 5 + } + + def testCorrectness[T: Ordering](n: Int, mkKey: Int => T) { + val o = implicitly[Ordering[T]] + val s = HashMap.empty[T, Unit] ++ (0 until n).map(x => mkKey(x) -> (())) + for (i <- 0 until n) { + val ki = mkKey(i) + val a = s.filter(kv => o.lt(kv._1, ki)) + val b = s.filterNot(kv => o.lt(kv._1, ki)) + require(a.size == i && (0 until i).forall(i => a.contains(mkKey(i)))) + require(b.size == n - i && (i until n).forall(i => b.contains(mkKey(i)))) + } + } + + // this tests the structural sharing of the new filter + // I could not come up with a simple test that tests structural sharing when only parts are reused, but + // at least this fails with the old and passes with the new implementation + def testSharing() { + val s = HashMap.empty[Int, Unit] ++ (0 until 100).map(_ -> (())) + require(s.filter(_ => true) eq s) + require(s.filterNot(_ => false) eq s) + } + + // this tests that neither hashCode nor equals are called during filter + def testNoHashing() { + var hashCount = 0 + var equalsCount = 0 + case class HashCounter(value: Int) extends Ordered[HashCounter] { + def compare(that: HashCounter) = value compare that.value + + override def hashCode = { + hashCount += 1 + value + } + + override def equals(that: Any) = { + equalsCount += 1 + this match { + case HashCounter(value) => this.value == value + case _ => false + } + } + } + + val s = HashMap.empty[HashCounter, Unit] ++ (0 until 100).map(k => HashCounter(k) -> (())) + val hashCount0 = hashCount + val equalsCount0 = equalsCount + val t = s.filter(_._1 < HashCounter(50)) + require(hashCount == hashCount0) + require(equalsCount == equalsCount0) + } + + // this tests correctness of filter and filterNot for integer keys + testCorrectness[Int](100, identity _) + // this tests correctness of filter and filterNot for keys with lots of collisions + // this is necessary because usually collisions are rare so the collision-related code is not thoroughly tested + testCorrectness[Collision](100, Collision.apply _) + testSharing() + testNoHashing() +} diff --git a/test/files/run/t6253a.scala b/test/files/run/t6253a.scala new file mode 100644 index 0000000000..efa3230df6 --- /dev/null +++ b/test/files/run/t6253a.scala @@ -0,0 +1,64 @@ +import scala.collection.immutable.HashSet + +object Test extends App { + + var hashCount = 0 + + /** + * A key that produces lots of hash collisions, to exercise the part of the code that deals with those + */ + case class Collision(value: Int) { + + override def hashCode = { + // we do not check hash counts for Collision keys because ListSet.++ uses a mutable hashset internally, + // so when we have hash collisions, union will call key.hashCode. + // hashCount += 1 + value / 5 + } + } + + /** + * A key that is identical to int other than that it counts hashCode invocations + */ + case class HashCounter(value: Int) { + + override def hashCode = { + hashCount += 1 + value + } + } + + def testUnion[T](sizes: Seq[Int], offsets: Seq[Double], keyType: String, mkKey: Int => T) { + for { + i <- sizes + o <- offsets + } { + val e = HashSet.empty[T] + val j = (i * o).toInt + // create two sets of size i with overlap o + val a = e ++ (0 until i).map(mkKey) + require(a.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val b = e ++ (j until (i + j)).map(mkKey) + require(b.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val as = e ++ (0 until j).map(mkKey) + require(as.size == j, s"Building HashSet of size $j failed. Key type $keyType.") + val hashCount0 = hashCount + val u = a union b + require(hashCount == hashCount0, s"key.hashCode should not be called, but has been called ${hashCount - hashCount0} times. Key type $keyType.") + require(u == (a union scala.collection.mutable.HashSet(b.toSeq: _*)), s"Operation must still work for other sets!") + require(u.size == i + j, s"Expected size ${i+j}. Real size ${u.size}. Key type $keyType.") + for (x <- 0 until i + j) + require(u.contains(mkKey(x)), s"Key type $keyType. Set (0 until ${i + j}) should contain $x but does not.") + val a_as = a union as + val as_a = as union a + require((a_as eq a) || (a_as eq as), s"No structural sharing in a union as. Key type $keyType, a=(0 until $i) as=(0 until $j)") + require((as_a eq a) || (as_a eq as), s"No structural sharing in as union a. Key type $keyType, a=(0 until $i) as=(0 until $j)") + } + } + + val sizes = Seq(1, 10, 100, 1000, 10000, 100000) + val offsets = Seq(0.0, 0.25, 0.5, 0.75, 1.0) + testUnion(sizes, offsets, "int", identity[Int]) + testUnion(sizes, offsets, "hashcounter", HashCounter.apply) + testUnion(sizes, offsets, "collision", Collision.apply) +} diff --git a/test/files/run/t6253b.scala b/test/files/run/t6253b.scala new file mode 100644 index 0000000000..9cbfefd49e --- /dev/null +++ b/test/files/run/t6253b.scala @@ -0,0 +1,62 @@ +import scala.collection.immutable.HashSet + +object Test extends App { + + var hashCount = 0 + + /** + * A key that produces lots of hash collisions, to exercise the part of the code that deals with those + */ + case class Collision(value: Int) { + + override def hashCode = { + hashCount += 1 + value / 5 + } + } + + /** + * A key that is identical to int other than that it counts hashCode invocations + */ + case class HashCounter(value: Int) { + + override def hashCode = { + hashCount += 1 + value + } + } + + def testIntersect[T](sizes: Seq[Int], offsets: Seq[Double], keyType: String, mkKey: Int => T) { + for { + i <- sizes + o <- offsets + } { + val e = HashSet.empty[T] + val j = (i * o).toInt + // create two sets of size i with overlap o + val a = e ++ (0 until i).map(mkKey) + require(a.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val b = e ++ (j until (i + j)).map(mkKey) + require(b.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val as = e ++ (0 until j).map(mkKey) + require(as.size == j, s"Building HashSet of size $j failed. Key type $keyType.") + val hashCount0 = hashCount + val u = a intersect b + require(hashCount == hashCount0, s"key.hashCode should not be called, but has been called ${hashCount - hashCount0} times. Key type $keyType.") + require(u == (a intersect scala.collection.mutable.HashSet(b.toSeq: _*)), s"Operation must still work for other sets!") + require(u.size == i - j, s"Expected size ${i + j}. Real size ${u.size}. Key type $keyType.") + for (x <- j until i) + require(u.contains(mkKey(x)), s"Key type $keyType. Set (0 until ${i + j}) should contain $x but does not.") + val a_as = a intersect as + val as_a = as intersect a + require((a_as eq as) || (a_as eq a), s"No structural sharing in a intersect as. Key type $keyType, a=(0 until $i) as=(0 until $j)") + require((as_a eq as) || (as_a eq a), s"No structural sharing in as intersect a. Key type $keyType, a=(0 until $i) as=(0 until $j)") + } + } + + val sizes = Seq(1, 10, 100, 1000, 10000, 100000) + val offsets = Seq(0.0, 0.25, 0.5, 0.75, 1.0) + testIntersect(sizes, offsets, "int", identity[Int]) + testIntersect(sizes, offsets, "hashcounter", HashCounter.apply) + testIntersect(sizes, offsets, "collision", Collision.apply) +} diff --git a/test/files/run/t6253c.scala b/test/files/run/t6253c.scala new file mode 100644 index 0000000000..71dfe1473e --- /dev/null +++ b/test/files/run/t6253c.scala @@ -0,0 +1,63 @@ +import scala.collection.immutable.HashSet + +object Test extends App { + + var hashCount = 0 + + /** + * A key that produces lots of hash collisions, to exercise the part of the code that deals with those + */ + case class Collision(value: Int) { + + override def hashCode = { + hashCount += 1 + value / 5 + } + } + + /** + * A key that is identical to int other than that it counts hashCode invocations + */ + case class HashCounter(value: Int) { + + override def hashCode = { + hashCount += 1 + value + } + } + + def testDiff[T](sizes: Seq[Int], offsets: Seq[Double], keyType: String, mkKey: Int => T) { + for { + i <- sizes + o <- offsets + } { + val e = HashSet.empty[T] + val j = (i * o).toInt + // create two sets of size i with overlap o + val a = e ++ (0 until i).map(mkKey) + require(a.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val b = e ++ (j until (i + j)).map(mkKey) + require(b.size == i, s"Building HashSet of size $i failed. Key type $keyType.") + val as = e ++ (0 until j).map(mkKey) + require(as.size == j, s"Building HashSet of size $j failed. Key type $keyType.") + val hashCount0 = hashCount + val u = a diff b + require(hashCount == hashCount0, s"key.hashCode should not be called, but has been called ${hashCount - hashCount0} times. Key type $keyType.") + require(u == (a diff scala.collection.mutable.HashSet(b.toSeq: _*)), s"Operation must still work for other sets!") + require(u.size == j, s"Expected size $j. Real size ${u.size}. Key type $keyType.") + for (x <- 0 until j) + require(u.contains(mkKey(x)), s"Key type $keyType. Set (0 until ${i + j}) should contain $x but does not.") + require((as intersect b).isEmpty) + val b_as = b diff as + val as_b = as diff b + require((b_as eq b) || (b_as eq as), s"No structural sharing in b diff as. Key type $keyType, b=($j until ${i + j}) as=(0 until $j)") + require((as_b eq b) || (as_b eq as), s"No structural sharing in as diff b. Key type $keyType, b=($j until ${i + j}) as=(0 until $j)") + } + } + + val sizes = Seq(1, 10, 100, 1000, 10000, 100000) + val offsets = Seq(0.0, 0.25, 0.5, 0.75, 1.0) + testDiff(sizes, offsets, "int", identity[Int]) + testDiff(sizes, offsets, "hashCounter", HashCounter.apply) + testDiff(sizes, offsets, "collision", Collision.apply) +} diff --git a/test/files/run/t6261.scala b/test/files/run/t6261.scala index b4463256c9..bf6d640de3 100644 --- a/test/files/run/t6261.scala +++ b/test/files/run/t6261.scala @@ -2,12 +2,6 @@ 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) @@ -92,7 +86,6 @@ object Test extends App { // StructureTests.printStructure(z) require(z.size == 2 && z.contains(a._1) && z.contains(c._1)) } - test0() test1() test2() test3() diff --git a/test/files/run/t6662/Test_2.scala b/test/files/run/t6662/Test_2.scala index 03a80b655a..82ac54cb46 100644 --- a/test/files/run/t6662/Test_2.scala +++ b/test/files/run/t6662/Test_2.scala @@ -2,7 +2,7 @@ object Test { def main(args: Array[String]) { - val s = Demo id () + val s = Demo id (()) println(s) } } diff --git a/test/files/run/t6863.check b/test/files/run/t6863.check index 030cb8b265..fea22b582f 100644 --- a/test/files/run/t6863.check +++ b/test/files/run/t6863.check @@ -10,3 +10,4 @@ t6863.scala:46: warning: comparing values of types Unit and Unit using `==' will t6863.scala:59: warning: comparing values of types Unit and Unit using `==' will always yield true assert({ () => x }.apply == ()) ^ +warning: there were 4 deprecation warning(s); re-run with -deprecation for details diff --git a/test/files/run/t6935.check b/test/files/run/t6935.check new file mode 100644 index 0000000000..844ca54682 --- /dev/null +++ b/test/files/run/t6935.check @@ -0,0 +1 @@ +warning: there were 1 deprecation warning(s); re-run with -deprecation for details diff --git a/test/files/run/t6935.scala b/test/files/run/t6935.scala index dea2d7f2e2..fdaf02e5ce 100644 --- a/test/files/run/t6935.scala +++ b/test/files/run/t6935.scala @@ -1,14 +1,14 @@ object Test { def main(args: Array[String]): Unit = { - import java.io._ - val bytes = new ByteArrayOutputStream() - val out = new ObjectOutputStream(bytes) - out.writeObject(()) - out.close() - val buf = bytes.toByteArray - val in = new ObjectInputStream(new ByteArrayInputStream(buf)) - val unit = in.readObject() - assert(unit == ()) + import java.io._ + val bytes = new ByteArrayOutputStream() + val out = new ObjectOutputStream(bytes) + out.writeObject(()) + out.close() + val buf = bytes.toByteArray + val in = new ObjectInputStream(new ByteArrayInputStream(buf)) + val unit = in.readObject() + assert(unit == ()) } } diff --git a/test/files/run/t7326.scala b/test/files/run/t7326.scala new file mode 100644 index 0000000000..ed9471ea8e --- /dev/null +++ b/test/files/run/t7326.scala @@ -0,0 +1,64 @@ +import scala.collection.immutable.ListSet +import scala.collection.immutable.HashSet + +object Test extends App { + + def testCorrectness() { + // a key that has many hashCode collisions + case class Collision(i: Int) { override def hashCode = i / 5 } + + def subsetTest[T](emptyA:Set[T], emptyB:Set[T], mkKey:Int => T, n:Int) { + val outside = mkKey(n + 1) + for(i <- 0 to n) { + val a = emptyA ++ (0 until i).map(mkKey) + // every set must be a subset of itself + require(a.subsetOf(a), "A set must be the subset of itself") + for(k <- 0 to i) { + // k <= i, so b is definitely a subset + val b = emptyB ++ (0 until k).map(mkKey) + // c has less elements than a, but contains a value that is not in a + // so it is not a subset, but that is not immediately obvious due to size + val c = b + outside + require(b.subsetOf(a), s"$b must be a subset of $a") + require(!c.subsetOf(a), s"$c must not be a subset of $a") + } + } + } + + // test the HashSet/HashSet case + subsetTest(HashSet.empty[Int], HashSet.empty[Int], identity, 100) + + // test the HashSet/other set case + subsetTest(HashSet.empty[Int], ListSet.empty[Int], identity, 100) + + // test the HashSet/HashSet case for Collision keys + subsetTest(HashSet.empty[Collision], HashSet.empty[Collision], Collision, 100) + + // test the HashSet/other set case for Collision keys + subsetTest(HashSet.empty[Collision], ListSet.empty[Collision], Collision, 100) + } + + /** + * A main performance benefit of the new subsetOf is that we do not have to call hashCode during subsetOf + * since we already have the hash codes in the HashSet1 nodes. + */ + def testNoHashCodeInvocationsDuringSubsetOf() = { + var count = 0 + + case class HashCodeCounter(i:Int) { + override def hashCode = { + count += 1 + i + } + } + + val a = HashSet.empty ++ (0 until 100).map(HashCodeCounter) + val b = HashSet.empty ++ (0 until 50).map(HashCodeCounter) + val count0 = count + val result = b.subsetOf(a) + require(count == count0, "key.hashCode must not be called during subsetOf of two HashSets") + result + } + testCorrectness() + testNoHashCodeInvocationsDuringSubsetOf() +} diff --git a/test/files/run/t7445.scala b/test/files/run/t7445.scala new file mode 100644 index 0000000000..e4ffeb8e1a --- /dev/null +++ b/test/files/run/t7445.scala @@ -0,0 +1,6 @@ +import scala.collection.immutable.ListMap + +object Test extends App { + val a = ListMap(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4, 5 -> 5); + require(a.tail == ListMap(2 -> 2, 3 -> 3, 4 -> 4, 5 -> 5)); +} diff --git a/test/files/run/t7700.check b/test/files/run/t7700.check new file mode 100644 index 0000000000..ca8e686984 --- /dev/null +++ b/test/files/run/t7700.check @@ -0,0 +1,2 @@ +public abstract java.lang.Object C.bar(java.lang.Object) +public abstract java.lang.Object C.foo(java.lang.Object) diff --git a/test/files/run/t7700.scala b/test/files/run/t7700.scala new file mode 100644 index 0000000000..76d16b808c --- /dev/null +++ b/test/files/run/t7700.scala @@ -0,0 +1,17 @@ +import scala.annotation._ + +trait C[@specialized U] { + @unspecialized + def foo(u: U): U + @unspecialized + def bar[A](u: U) = u +} + +object Test extends App { + val declared = classOf[C[_]].getDeclaredMethods.sortBy(_.getName) + println(declared.mkString("\n")) + object CInt extends C[Int] { def foo(i: Int) = i } + object CAny extends C[Any] { def foo(a: Any) = a } + assert(CInt.foo(1) == 1) + assert(CAny.foo("") == "") +} diff --git a/test/files/run/t8015-ffc.scala b/test/files/run/t8015-ffc.scala new file mode 100644 index 0000000000..fe6781be42 --- /dev/null +++ b/test/files/run/t8015-ffc.scala @@ -0,0 +1,7 @@ + +object Test extends App { + val ms = """This is a long multiline string + with \u000d\u000a CRLF embedded.""" + assert(ms.lines.size == 3, s"lines.size ${ms.lines.size}") + assert(ms contains "\r\n CRLF", "no CRLF") +} diff --git a/test/files/run/t8100.check b/test/files/run/t8100.check new file mode 100644 index 0000000000..cdd927fd88 --- /dev/null +++ b/test/files/run/t8100.check @@ -0,0 +1 @@ +Success(0) diff --git a/test/files/run/t8100.scala b/test/files/run/t8100.scala new file mode 100644 index 0000000000..b9d0fe5003 --- /dev/null +++ b/test/files/run/t8100.scala @@ -0,0 +1,8 @@ +object Test { + import scala.util.Try + + def main(args: Array[String]): Unit = { + def stream = Stream.from(0).take(100000).map(n => None) + println(Try(stream.flatten.length)) + } +} diff --git a/test/files/run/t8133/A_1.scala b/test/files/run/t8133/A_1.scala new file mode 100644 index 0000000000..a2836cdb3a --- /dev/null +++ b/test/files/run/t8133/A_1.scala @@ -0,0 +1,5 @@ +// a.scala +package object pkg { + class AnyOps(val x: Any) extends AnyVal + def AnyOps(x: Any) = new AnyOps(x) +} diff --git a/test/files/run/t8133/B_2.scala b/test/files/run/t8133/B_2.scala new file mode 100644 index 0000000000..b80e10952d --- /dev/null +++ b/test/files/run/t8133/B_2.scala @@ -0,0 +1,15 @@ +package pkg { + package object other + package other { + class Crash { + AnyOps(0) + () + } + } +} + +object Test { + def main(args: Array[String]): Unit = { + new pkg.other.Crash + } +} diff --git a/test/files/run/t8133b/A_1.scala b/test/files/run/t8133b/A_1.scala new file mode 100644 index 0000000000..24bbfc118d --- /dev/null +++ b/test/files/run/t8133b/A_1.scala @@ -0,0 +1,4 @@ +package object pkg { + def foo(x: Int): String = "a" + def foo(x: String): String = "b" +} diff --git a/test/files/run/t8133b/B_2.scala b/test/files/run/t8133b/B_2.scala new file mode 100644 index 0000000000..865ca0c0b0 --- /dev/null +++ b/test/files/run/t8133b/B_2.scala @@ -0,0 +1,9 @@ +// b.scala +package pkg { + package object other + package other { class Crash { foo("") } } +} + +object Test { + def main(args: Array[String]): Unit = new pkg.other.Crash +} diff --git a/test/files/run/t8199.scala b/test/files/run/t8199.scala new file mode 100644 index 0000000000..50994159ed --- /dev/null +++ b/test/files/run/t8199.scala @@ -0,0 +1,105 @@ +class reallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongname { +object obj0 +object obj01 +object obj012 +object obj0123 +object obj01234 +object obj012345 +object obj0123456 +object obj01234567 +object obj012345678 +object obj0123456789 +object obj01234567890 +class cls0 +class cls01 +class cls012 +class cls0123 +class cls01234 +class cls012345 +class cls0123456 +class cls01234567 +class cls012345678 +class cls0123456789 +class cls01234567890 +trait trt0 { def x = Test.checkCallerImplClassName() } +trait trt01 { def x = Test.checkCallerImplClassName() } +trait trt012 { def x = Test.checkCallerImplClassName() } +trait trt0123 { def x = Test.checkCallerImplClassName() } +trait trt01234 { def x = Test.checkCallerImplClassName() } +trait trt012345 { def x = Test.checkCallerImplClassName() } +trait trt0123456 { def x = Test.checkCallerImplClassName() } +trait trt01234567 { def x = Test.checkCallerImplClassName() } +trait trt012345678 { def x = Test.checkCallerImplClassName() } +trait trt0123456789 { def x = Test.checkCallerImplClassName() } +trait trt01234567890 { def x = Test.checkCallerImplClassName() } +} + +object Test extends App { + def check(c: Class[_]) { + checkClassName(c.getName) + } + def checkClassName(name: String) { + val defaultMaxClassFileLength = 255 + assert((name + ".class").length <= defaultMaxClassFileLength, name) + } + def checkCallerImplClassName() { + val name = Thread.currentThread.getStackTrace.apply(2).getClassName + assert(name.contains("$class")) + Test.checkClassName(name) + } + + val c = new reallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongname + import c._ + + check(obj0.getClass) + check(obj01.getClass) + check(obj012.getClass) + check(obj0123.getClass) + check(obj01234.getClass) + check(obj012345.getClass) + check(obj0123456.getClass) + check(obj01234567.getClass) + check(obj012345678.getClass) + check(obj0123456789.getClass) + check(obj01234567890.getClass) + + check(classOf[cls0]) + check(classOf[cls01]) + check(classOf[cls012]) + check(classOf[cls0123]) + check(classOf[cls01234]) + check(classOf[cls012345]) + check(classOf[cls0123456]) + check(classOf[cls01234567]) + check(classOf[cls012345678]) + check(classOf[cls0123456789]) + check(classOf[cls01234567890]) + + // interface facets + check(classOf[trt0]) + check(classOf[trt01]) + check(classOf[trt012]) + check(classOf[trt0123]) + check(classOf[trt01234]) + check(classOf[trt012345]) + check(classOf[trt0123456]) + check(classOf[trt01234567]) + check(classOf[trt012345678]) + check(classOf[trt0123456789]) + check(classOf[trt01234567890]) + + // impl classes are harder to find the names of to test! + (new trt0 {}).x + (new trt01 {}).x + (new trt012 {}).x + (new trt0123 {}).x + (new trt01234 {}).x + (new trt012345 {}).x + (new trt0123456 {}).x + (new trt01234567 {}).x + (new trt012345678 {}).x + (new trt0123456789 {}).x + (new trt01234567890 {}).x +} + +// filename too long: reallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongnamereallylongname$obj012345$.class diff --git a/test/files/run/t8233-bcode.flags b/test/files/run/t8233-bcode.flags new file mode 100644 index 0000000000..c30091d3de --- /dev/null +++ b/test/files/run/t8233-bcode.flags @@ -0,0 +1 @@ +-Ybackend:GenBCode diff --git a/test/files/run/t8233-bcode.scala b/test/files/run/t8233-bcode.scala new file mode 100644 index 0000000000..fae1c2b702 --- /dev/null +++ b/test/files/run/t8233-bcode.scala @@ -0,0 +1,18 @@ +object Test { + def bar(s: String) = s; + val o: Option[Null] = None + def nullReference { + val a: Null = o.get + bar(a) // Was: VerifyError under GenICode + } + + def literal { + val a: Null = null + bar(a) + } + + def main(args: Array[String]) = { + try { nullReference } catch { case _: NoSuchElementException => } + literal + } +} diff --git a/test/files/run/t8233.scala b/test/files/run/t8233.scala new file mode 100644 index 0000000000..fae1c2b702 --- /dev/null +++ b/test/files/run/t8233.scala @@ -0,0 +1,18 @@ +object Test { + def bar(s: String) = s; + val o: Option[Null] = None + def nullReference { + val a: Null = o.get + bar(a) // Was: VerifyError under GenICode + } + + def literal { + val a: Null = null + bar(a) + } + + def main(args: Array[String]) = { + try { nullReference } catch { case _: NoSuchElementException => } + literal + } +} diff --git a/test/files/run/var-arity-class-symbol.scala b/test/files/run/var-arity-class-symbol.scala new file mode 100644 index 0000000000..29fe960eb3 --- /dev/null +++ b/test/files/run/var-arity-class-symbol.scala @@ -0,0 +1,19 @@ +import scala.reflect.runtime.universe._, definitions._ +object Test extends App { + // Tuples + assert(TupleClass.seq.size == 22) + assert(TupleClass(0) == NoSymbol) + assert(TupleClass(23) == NoSymbol) + assert((1 to 22).forall { i => TupleClass(i).name.toString == s"Tuple$i" }) + // Functions + assert(FunctionClass.seq.size == 23) + assert(FunctionClass(-1) == NoSymbol) + assert(FunctionClass(23) == NoSymbol) + assert((0 to 22).forall { i => FunctionClass(i).name.toString == s"Function$i" }) + // Products + assert(ProductClass.seq.size == 23) + assert(ProductClass(-1) == NoSymbol) + assert(ProductClass(0) == UnitClass) + assert(ProductClass(23) == NoSymbol) + assert((1 to 22).forall { i => ProductClass(i).name.toString == s"Product$i" }) +} |