diff options
author | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
commit | a45a78a1d4111709acdc0bca9a1ac869a8e53ea5 (patch) | |
tree | 5c909c41db2470c460cbb3c33672294c9342b914 /test/files | |
parent | 26de4394b19d6614b7d414b33f66ebf7adcb8833 (diff) | |
parent | 644eb7078a11613a06dcaaefb807cbcc44f65ea7 (diff) | |
download | scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.gz scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.bz2 scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.zip |
Merge commit '644eb7078a' into wip/fresh-merge2
Conflicts:
build.xml
src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
Diffstat (limited to 'test/files')
21 files changed, 204 insertions, 120 deletions
diff --git a/test/files/jvm/bytecode-test-example.check b/test/files/jvm/bytecode-test-example.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/jvm/bytecode-test-example.check @@ -0,0 +1 @@ +2 diff --git a/test/files/jvm/bytecode-test-example/Foo_1.scala b/test/files/jvm/bytecode-test-example/Foo_1.scala new file mode 100644 index 0000000000..4f679d156f --- /dev/null +++ b/test/files/jvm/bytecode-test-example/Foo_1.scala @@ -0,0 +1,9 @@ +class Foo_1 { + def foo(x: AnyRef): Int = { + val bool = x == null + if (x != null) + 1 + else + 0 + } +} diff --git a/test/files/jvm/bytecode-test-example/Test.scala b/test/files/jvm/bytecode-test-example/Test.scala new file mode 100644 index 0000000000..d668059cb7 --- /dev/null +++ b/test/files/jvm/bytecode-test-example/Test.scala @@ -0,0 +1,32 @@ +import scala.tools.partest.BytecodeTest + +import scala.tools.nsc.util.JavaClassPath +import java.io.InputStream +import scala.tools.asm +import asm.ClassReader +import asm.tree.{ClassNode, InsnList} +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + println(countNullChecks(methodNode.instructions)) + } + + def countNullChecks(insnList: InsnList): Int = { + /** Is given instruction a null check? + * NOTE + * This will detect direct null compparsion as in + * if (x == null) ... + * and not indirect as in + * val foo = null + * if (x == foo) ... + */ + def isNullCheck(node: asm.tree.AbstractInsnNode): Boolean = { + val opcode = node.getOpcode + (opcode == asm.Opcodes.IFNULL) || (opcode == asm.Opcodes.IFNONNULL) + } + insnList.iterator.asScala.count(isNullCheck) + } +} diff --git a/test/files/jvm/throws-annot-from-java.check b/test/files/jvm/throws-annot-from-java.check new file mode 100644 index 0000000000..be3ba412f8 --- /dev/null +++ b/test/files/jvm/throws-annot-from-java.check @@ -0,0 +1,47 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :power +** Power User mode enabled - BEEP WHIR GYVE ** +** :phase has been set to 'typer'. ** +** scala.tools.nsc._ has been imported ** +** global._, definitions._ also imported ** +** Try :help, :vals, power.<tab> ** + +scala> :paste +// Entering paste mode (ctrl-D to finish) + +{ + val clazz = rootMirror.getClassByName(newTermName("test.ThrowsDeclaration_2")); + { + val method = clazz.info.member(newTermName("foo")) + val throwsAnn = method.annotations.head + val atp = throwsAnn.atp + println("foo") + println("atp.typeParams.isEmpty: " + atp.typeParams.isEmpty) + println(throwsAnn) + } + println + + { + val method = clazz.info.member(newTermName("bar")) + val throwsAnn = method.annotations.head + val Literal(const) = throwsAnn.args.head + val tp = const.typeValue + println("bar") + println("tp.typeParams.isEmpty: " + tp.typeParams.isEmpty) + println(throwsAnn) + } +} + +// Exiting paste mode, now interpreting. + +foo +atp.typeParams.isEmpty: true +throws[IllegalStateException](classOf[java.lang.IllegalStateException]) + +bar +tp.typeParams.isEmpty: true +throws[test.PolymorphicException[_]](classOf[test.PolymorphicException]) + +scala> diff --git a/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala b/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala new file mode 100644 index 0000000000..58fa536f0b --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/PolymorphicException_1.scala @@ -0,0 +1,3 @@ +package test + +class PolymorphicException[T] extends Exception diff --git a/test/files/jvm/throws-annot-from-java/Test_3.scala b/test/files/jvm/throws-annot-from-java/Test_3.scala new file mode 100644 index 0000000000..de1d984573 --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/Test_3.scala @@ -0,0 +1,29 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """:power +:paste +{ + val clazz = rootMirror.getClassByName(newTermName("test.ThrowsDeclaration_2")); + { + val method = clazz.info.member(newTermName("foo")) + val throwsAnn = method.annotations.head + val atp = throwsAnn.atp + println("foo") + println("atp.typeParams.isEmpty: " + atp.typeParams.isEmpty) + println(throwsAnn) + } + println + + { + val method = clazz.info.member(newTermName("bar")) + val throwsAnn = method.annotations.head + val Literal(const) = throwsAnn.args.head + val tp = const.typeValue + println("bar") + println("tp.typeParams.isEmpty: " + tp.typeParams.isEmpty) + println(throwsAnn) + } +} +""" +} diff --git a/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java b/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java new file mode 100644 index 0000000000..3708fe626b --- /dev/null +++ b/test/files/jvm/throws-annot-from-java/ThrowsDeclaration_2.java @@ -0,0 +1,6 @@ +package test; + +public class ThrowsDeclaration_2 { + public void foo() throws IllegalStateException {}; + public void bar() throws PolymorphicException {}; +} diff --git a/test/files/neg/t5589neg.check b/test/files/neg/t5589neg.check deleted file mode 100644 index f1dad94df3..0000000000 --- a/test/files/neg/t5589neg.check +++ /dev/null @@ -1,37 +0,0 @@ -t5589neg.scala:2: warning: `withFilter' method does not yet exist on scala.util.Either.RightProjection[Int,String], using `filter' method instead - def f5(x: Either[Int, String]) = for ((y1, y2: String) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:2: error: constructor cannot be instantiated to expected type; - found : (T1, T2) - required: String - def f5(x: Either[Int, String]) = for ((y1, y2: String) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:3: warning: `withFilter' method does not yet exist on scala.util.Either.RightProjection[Int,String], using `filter' method instead - def f6(x: Either[Int, String]) = for ((y1, y2: Any) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:3: error: constructor cannot be instantiated to expected type; - found : (T1, T2) - required: String - def f6(x: Either[Int, String]) = for ((y1, y2: Any) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:4: error: constructor cannot be instantiated to expected type; - found : (T1,) - required: (String, Int) - def f7(x: Either[Int, (String, Int)]) = for (y1 @ Tuple1(y2) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:4: error: not found: value y2 - def f7(x: Either[Int, (String, Int)]) = for (y1 @ Tuple1(y2) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:5: error: constructor cannot be instantiated to expected type; - found : (T1, T2, T3) - required: (String, Int) - def f8(x: Either[Int, (String, Int)]) = for ((y1, y2, y3) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:5: error: not found: value y1 - def f8(x: Either[Int, (String, Int)]) = for ((y1, y2, y3) <- x.right) yield ((y1, y2)) - ^ -t5589neg.scala:5: error: not found: value y2 - def f8(x: Either[Int, (String, Int)]) = for ((y1, y2, y3) <- x.right) yield ((y1, y2)) - ^ -two warnings found -7 errors found diff --git a/test/files/neg/t5589neg.scala b/test/files/neg/t5589neg.scala deleted file mode 100644 index 31ff2c3693..0000000000 --- a/test/files/neg/t5589neg.scala +++ /dev/null @@ -1,6 +0,0 @@ -class A { - def f5(x: Either[Int, String]) = for ((y1, y2: String) <- x.right) yield ((y1, y2)) - def f6(x: Either[Int, String]) = for ((y1, y2: Any) <- x.right) yield ((y1, y2)) - def f7(x: Either[Int, (String, Int)]) = for (y1 @ Tuple1(y2) <- x.right) yield ((y1, y2)) - def f8(x: Either[Int, (String, Int)]) = for ((y1, y2, y3) <- x.right) yield ((y1, y2)) -} diff --git a/test/files/neg/t5589neg2.scala b/test/files/neg/t5589neg2.scala deleted file mode 100644 index b7c7ab7218..0000000000 --- a/test/files/neg/t5589neg2.scala +++ /dev/null @@ -1,13 +0,0 @@ -class A { - def f1(x: List[((((Int, (Double, (Float, String))), List[String]), List[Int]), List[Float])]) = { - for (((((a, (b, (c, d))), es), fs), gs) <- x) yield (d :: es).mkString(", ") // ok - } - - def f2(x: List[((((Int, (Double, (Float, String))), List[String]), List[Int]), List[Float])]) = { - for (((((a, (b, (c, (d1, d2)))), es), fs), gs) <- x) yield (d :: es).mkString(", ") // not ok - } - - def f3(x: List[((((Int, (Double, (Float, String))), List[String]), List[Int]), List[Float])]) = { - for (((((a, (b, _)), es), fs), gs) <- x) yield (es ::: fs).mkString(", ") // ok - } -}
\ No newline at end of file diff --git a/test/files/neg/t6728.check b/test/files/neg/t6728.check new file mode 100644 index 0000000000..d853d6f724 --- /dev/null +++ b/test/files/neg/t6728.check @@ -0,0 +1,4 @@ +t6728.scala:4: error: '(' expected but '}' found. + } + ^ +one error found diff --git a/test/files/neg/t6728.scala b/test/files/neg/t6728.scala new file mode 100644 index 0000000000..ba0b1a0fdf --- /dev/null +++ b/test/files/neg/t6728.scala @@ -0,0 +1,5 @@ +object X { + while(true) { + for + } +} diff --git a/test/files/pos/t1336.scala b/test/files/pos/t1336.scala deleted file mode 100644 index 63967985c7..0000000000 --- a/test/files/pos/t1336.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Foo { - def foreach( f : ((Int,Int)) => Unit ) { - println("foreach") - f(1,2) - } - - for( (a,b) <- this ) { - println((a,b)) - } -} diff --git a/test/files/pos/t5589.scala b/test/files/pos/t5589.scala deleted file mode 100644 index 69cbb20391..0000000000 --- a/test/files/pos/t5589.scala +++ /dev/null @@ -1,22 +0,0 @@ -class A { - // First three compile. - def f1(x: Either[Int, String]) = x.right map (y => y) - def f2(x: Either[Int, String]) = for (y <- x.right) yield y - def f3(x: Either[Int, (String, Int)]) = x.right map { case (y1, y2) => (y1, y2) } - // Last one fails. - def f4(x: Either[Int, (String, Int)]) = for ((y1, y2) <- x.right) yield ((y1, y2)) -/** -./a.scala:5: error: constructor cannot be instantiated to expected type; - found : (T1, T2) - required: Either[Nothing,(String, Int)] - def f4(x: Either[Int, (String, Int)]) = for ((y1, y2) <- x.right) yield ((y1, y2)) - ^ -./a.scala:5: error: not found: value y1 - def f4(x: Either[Int, (String, Int)]) = for ((y1, y2) <- x.right) yield ((y1, y2)) - ^ -./a.scala:5: error: not found: value y2 - def f4(x: Either[Int, (String, Int)]) = for ((y1, y2) <- x.right) yield ((y1, y2)) - ^ -three errors found -**/ -} diff --git a/test/files/pos/t7035.scala b/test/files/pos/t7035.scala new file mode 100644 index 0000000000..f45bd0a878 --- /dev/null +++ b/test/files/pos/t7035.scala @@ -0,0 +1,15 @@ +case class Y(final var x: Int, final private var y: String, final val z1: Boolean, final private val z2: Any) { + + import Test.{y => someY} + List(someY.x: Int, someY.y: String, someY.z1: Boolean, someY.z2: Any) + someY.y = "" +} + +object Test { + val y = Y(0, "", true, new {}) + val unapp: Option[(Int, String, Boolean, Any)] = // was (Int, Boolean, String, Any) !! + Y.unapply(y) + + val Y(a, b, c, d) = y + List(a: Int, b: String, c: Boolean, d: Any) +} diff --git a/test/files/run/reify-staticXXX.scala b/test/files/run/reify-staticXXX.scala index dc861f843e..e80157dd8f 100644 --- a/test/files/run/reify-staticXXX.scala +++ b/test/files/run/reify-staticXXX.scala @@ -4,12 +4,12 @@ import scala.tools.reflect.Eval object B { override def toString = "object" } class C { override def toString = "class" } -package foo { +package foo1 { object B { override def toString = "package > object" } class C { override def toString = "package > class" } } -object foo { +object Foo2 { object B { override def toString = "object > object" } class C { override def toString = "object > class" } } @@ -20,14 +20,14 @@ object packageless { println(reify(B).eval) println(new C) println(reify(new C).eval) - println(foo.B) - println(reify(foo.B).eval) - println(new foo.C) - println(reify(new foo.C).eval) - println(_root_.foo.B) - println(reify(_root_.foo.B).eval) - println(new _root_.foo.C) - println(reify(new _root_.foo.C).eval) + println(Foo2.B) + println(reify(Foo2.B).eval) + println(new Foo2.C) + println(reify(new Foo2.C).eval) + println(_root_.foo1.B) + println(reify(_root_.foo1.B).eval) + println(new _root_.foo1.C) + println(reify(new _root_.foo1.C).eval) } } @@ -38,14 +38,14 @@ package packageful { println(reify(B).eval) println(new C) println(reify(new C).eval) - println(foo.B) - println(reify(foo.B).eval) - println(new foo.C) - println(reify(new foo.C).eval) - println(_root_.foo.B) - println(reify(_root_.foo.B).eval) - println(new _root_.foo.C) - println(reify(new _root_.foo.C).eval) + println(Foo2.B) + println(reify(Foo2.B).eval) + println(new Foo2.C) + println(reify(new Foo2.C).eval) + println(_root_.foo1.B) + println(reify(_root_.foo1.B).eval) + println(new _root_.foo1.C) + println(reify(new _root_.foo1.C).eval) } } } diff --git a/test/files/run/t4574.scala b/test/files/run/t4574.scala deleted file mode 100644 index 1dde496aca..0000000000 --- a/test/files/run/t4574.scala +++ /dev/null @@ -1,13 +0,0 @@ -object Test { - val xs: List[(Int, Int)] = List((2, 2), null) - - def expectMatchError[T](msg: String)(body: => T) { - try { body ; assert(false, "Should not succeed.") } - catch { case _: MatchError => println(msg) } - } - - def main(args: Array[String]): Unit = { - expectMatchError("I hereby refute null!")( for ((x, y) <- xs) yield x ) - expectMatchError("I denounce null as unListLike!")( (null: Any) match { case List(_*) => true } ) - } -} diff --git a/test/files/run/t6669.scala b/test/files/run/t6669.scala new file mode 100644 index 0000000000..b55718b12b --- /dev/null +++ b/test/files/run/t6669.scala @@ -0,0 +1,26 @@ +import java.io.{ByteArrayOutputStream, PrintStream} + +object Test extends App { + val baos = new ByteArrayOutputStream() + val ps = new PrintStream(baos) + + // first test with the default classpath + (scala.Console withOut ps) { + scala.tools.scalap.Main.main(Array("-verbose", "java.lang.Object")) + } + + // now make sure we saw the '.' in the classpath + val msg1 = baos.toString() + assert(msg1 contains "directory classpath: .", s"Did not see '.' in the default class path. Full results were:\n$msg1") + + // then test again with a user specified classpath + baos.reset + + (scala.Console withOut ps) { + scala.tools.scalap.Main.main(Array("-verbose", "-cp", "whatever", "java.lang.Object")) + } + + // now make sure we did not see the '.' in the classpath + val msg2 = baos.toString() + assert(!(msg2 contains "directory classpath: ."), s"Did saw '.' in the user specified class path. Full results were:\n$msg2") +} diff --git a/test/files/run/t6968.check b/test/files/run/t6968.check new file mode 100644 index 0000000000..7a18941537 --- /dev/null +++ b/test/files/run/t6968.check @@ -0,0 +1 @@ +1, 3, 5 diff --git a/test/files/run/t6968.scala b/test/files/run/t6968.scala new file mode 100644 index 0000000000..b5cadfd9e1 --- /dev/null +++ b/test/files/run/t6968.scala @@ -0,0 +1,7 @@ +object Test { + def main(args: Array[String]) { + val mixedList = List(1,(1,2),4,(3,1),(5,4),6) + val as = for((a,b) <- mixedList) yield a + println(as.mkString(", ")) + } +} diff --git a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala b/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala index 05237bace8..b6af8f41bd 100644 --- a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala +++ b/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala @@ -20,7 +20,7 @@ abstract class ParallelMapCheck[K, V](collname: String) extends ParallelIterable property("gets iterated keys") = forAll(collectionPairs) { case (t, coll) => val containsT = for ((k, v) <- t) yield (coll.get(k) == Some(v)) - val containsSelf = for ((k, v) <- coll) yield (coll.get(k) == Some(v)) + val containsSelf = coll.map { case (k, v) => coll.get(k) == Some(v) } ("Par contains elements of seq map" |: containsT.forall(_ == true)) && ("Par contains elements of itself" |: containsSelf.forall(_ == true)) } |