diff options
Diffstat (limited to 'test/files/jvm')
45 files changed, 468 insertions, 80 deletions
diff --git a/test/files/jvm/constant-optimization/Foo_1.flags b/test/files/jvm/constant-optimization/Foo_1.flags new file mode 100644 index 0000000000..86f52af447 --- /dev/null +++ b/test/files/jvm/constant-optimization/Foo_1.flags @@ -0,0 +1 @@ +-Ynooptimise -Yconst-opt
\ No newline at end of file diff --git a/test/files/jvm/constant-optimization/Foo_1.scala b/test/files/jvm/constant-optimization/Foo_1.scala new file mode 100644 index 0000000000..cb67ad4e90 --- /dev/null +++ b/test/files/jvm/constant-optimization/Foo_1.scala @@ -0,0 +1,9 @@ +class Foo_1 { + def foo() { + // constant optimization should eliminate all branches + val i = 1 + val x = if (i != 1) null else "good" + val y = if (x == null) "good" else x + "" + println(y) + } +}
\ No newline at end of file diff --git a/test/files/jvm/constant-optimization/Test.scala b/test/files/jvm/constant-optimization/Test.scala new file mode 100644 index 0000000000..283aa6f47a --- /dev/null +++ b/test/files/jvm/constant-optimization/Test.scala @@ -0,0 +1,27 @@ + +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + val comparisons = Set(asm.Opcodes.IF_ACMPEQ, asm.Opcodes.IF_ACMPNE, asm.Opcodes.IF_ICMPEQ, asm.Opcodes.IF_ICMPGE, asm.Opcodes.IF_ICMPGT, asm.Opcodes.IF_ICMPLE, + asm.Opcodes.IF_ICMPLT, asm.Opcodes.IF_ICMPNE, asm.Opcodes.IFEQ, asm.Opcodes.IFGE, asm.Opcodes.IFGT, asm.Opcodes.IFLE, asm.Opcodes.IFLT, + asm.Opcodes.IFNE, asm.Opcodes.IFNONNULL, asm.Opcodes.IFNULL) + + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + // after optimization there should be no comparisons left + val expected = 0 + + val got = countComparisons(methodNode.instructions) + assert(got == expected, s"expected $expected but got $got comparisons") + } + + def countComparisons(insnList: InsnList): Int = { + def isComparison(node: asm.tree.AbstractInsnNode): Boolean = + (comparisons contains node.getOpcode) + insnList.iterator.asScala count isComparison + } +}
\ No newline at end of file diff --git a/test/files/jvm/duration-tck.scala b/test/files/jvm/duration-tck.scala index d0f13816a6..b2573448c7 100644 --- a/test/files/jvm/duration-tck.scala +++ b/test/files/jvm/duration-tck.scala @@ -176,8 +176,9 @@ object Test extends App { Thread.sleep(1.second.toMillis) - { val l = dead.timeLeft; assert(l <= 1.second, s"$l > 1.second") } - { val l = dead2.timeLeft; assert(l <= 1.second, s"$l > 1.second") } + // unfortunately it can happen that the sleep() returns early without throwing + { val l = dead.timeLeft; assert(l <= 1100.millis, s"$l > 1100.millis") } + { val l = dead2.timeLeft; assert(l <= 1100.millis, s"$l > 1100.millis") } // test integer mul/div diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index ddd819c109..7deb4929d4 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -96,7 +96,7 @@ object FutureTests extends MinimalScalaTest { val logThrowable: Throwable => Unit = p.trySuccess(_) val ec: ExecutionContext = ExecutionContext.fromExecutor(null, logThrowable) - val t = new NotImplementedError("foo") + val t = new InterruptedException() val f = Future(throw t)(ec) Await.result(p.future, 2.seconds) mustBe t } diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index 96b57c7742..44930c2932 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -357,10 +357,8 @@ defined class Term scala> def f(e: Exp) = e match { // non-exhaustive warning here case _:Fact => 3 } -<console>:18: warning: match is not exhaustive! -missing combination Exp -missing combination Term - +<console>:18: warning: match may not be exhaustive. +It would fail on the following inputs: Exp(), Term() def f(e: Exp) = e match { // non-exhaustive warning here ^ f: (e: Exp)Int diff --git a/test/files/jvm/interpreter.scala b/test/files/jvm/interpreter.scala index f45eb034a9..bd1851053f 100644 --- a/test/files/jvm/interpreter.scala +++ b/test/files/jvm/interpreter.scala @@ -2,7 +2,7 @@ import scala.tools.nsc._ import scala.tools.partest.ReplTest object Test extends ReplTest { - override def extraSettings = "-deprecation -Xoldpatmat" + override def extraSettings = "-deprecation" def code = <code> // basics 3+4 diff --git a/test/files/jvm/manifests-new.scala b/test/files/jvm/manifests-new.scala index f730be67bb..3937fdec69 100644 --- a/test/files/jvm/manifests-new.scala +++ b/test/files/jvm/manifests-new.scala @@ -56,7 +56,7 @@ object Test1 extends TestUtil { } object Test2 { - import scala.util.Marshal._ + import Marshal._ println("()="+load[Unit](dump(()))) println("true="+load[Boolean](dump(true))) println("a="+load[Char](dump('a'))) @@ -88,6 +88,38 @@ object Test2 { println() } +object Marshal { + import java.io._ + import scala.reflect.ClassTag + + def dump[A](o: A)(implicit t: ClassTag[A]): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(t) + out.writeObject(o) + out.close() + ba.toByteArray() + } + + @throws(classOf[IOException]) + @throws(classOf[ClassCastException]) + @throws(classOf[ClassNotFoundException]) + def load[A](buffer: Array[Byte])(implicit expected: ClassTag[A]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + val found = in.readObject.asInstanceOf[ClassTag[_]] + try { + found.runtimeClass.asSubclass(expected.runtimeClass) + in.readObject.asInstanceOf[A] + } catch { + case _: ClassCastException => + in.close() + throw new ClassCastException("type mismatch;"+ + "\n found : "+found+ + "\n required: "+expected) + } + } +} + trait TestUtil { import java.io._ def write[A](o: A): Array[Byte] = { diff --git a/test/files/jvm/manifests-old.scala b/test/files/jvm/manifests-old.scala index 241966fd9d..bb1928f094 100644 --- a/test/files/jvm/manifests-old.scala +++ b/test/files/jvm/manifests-old.scala @@ -55,7 +55,7 @@ object Test1 extends TestUtil { } object Test2 { - import scala.util.Marshal._ + import Marshal._ println("()="+load[Unit](dump(()))) println("true="+load[Boolean](dump(true))) println("a="+load[Char](dump('a'))) @@ -87,6 +87,38 @@ object Test2 { println() } +object Marshal { + import java.io._ + import scala.reflect.ClassTag + + def dump[A](o: A)(implicit t: ClassTag[A]): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(t) + out.writeObject(o) + out.close() + ba.toByteArray() + } + + @throws(classOf[IOException]) + @throws(classOf[ClassCastException]) + @throws(classOf[ClassNotFoundException]) + def load[A](buffer: Array[Byte])(implicit expected: ClassTag[A]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + val found = in.readObject.asInstanceOf[ClassTag[_]] + try { + found.runtimeClass.asSubclass(expected.runtimeClass) + in.readObject.asInstanceOf[A] + } catch { + case _: ClassCastException => + in.close() + throw new ClassCastException("type mismatch;"+ + "\n found : "+found+ + "\n required: "+expected) + } + } +} + trait TestUtil { import java.io._ def write[A](o: A): Array[Byte] = { diff --git a/test/files/jvm/named-args-in-order.check b/test/files/jvm/named-args-in-order.check new file mode 100644 index 0000000000..29a3ba55d3 --- /dev/null +++ b/test/files/jvm/named-args-in-order.check @@ -0,0 +1,3 @@ +bytecode identical +bytecode identical +bytecode identical diff --git a/test/files/jvm/named-args-in-order/SameBytecode.scala b/test/files/jvm/named-args-in-order/SameBytecode.scala new file mode 100644 index 0000000000..c00641777e --- /dev/null +++ b/test/files/jvm/named-args-in-order/SameBytecode.scala @@ -0,0 +1,9 @@ +class SameBytecode { + def foo(a: Int, b: String) = 0 + def foo(a: Int, b: Any) = 0 + + def a = foo(0, "") + def b = foo(a = 0, "") + def c = foo(0, b = "") + def d = foo(a = 0, b = "") +}
\ No newline at end of file diff --git a/test/files/jvm/named-args-in-order/Test.scala b/test/files/jvm/named-args-in-order/Test.scala new file mode 100644 index 0000000000..36b9cbc1d1 --- /dev/null +++ b/test/files/jvm/named-args-in-order/Test.scala @@ -0,0 +1,10 @@ +import scala.tools.partest.BytecodeTest + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("SameBytecode") + def sameAsA(meth: String) = + sameBytecode(getMethod(classNode, "a"), getMethod(classNode, meth)) + Seq("b", "c", "d").foreach(sameAsA) + } +} diff --git a/test/files/jvm/non-fatal-tests.scala b/test/files/jvm/non-fatal-tests.scala index 471a9d227a..22c7cba51f 100644 --- a/test/files/jvm/non-fatal-tests.scala +++ b/test/files/jvm/non-fatal-tests.scala @@ -7,7 +7,8 @@ trait NonFatalTests { Seq(new StackOverflowError, new RuntimeException, new Exception, - new Throwable) + new Throwable, + new NotImplementedError) //Fatals val fatals: Seq[Throwable] = @@ -15,8 +16,7 @@ trait NonFatalTests { new OutOfMemoryError, new LinkageError, new VirtualMachineError {}, - new Throwable with scala.util.control.ControlThrowable, - new NotImplementedError) + new Throwable with scala.util.control.ControlThrowable) def testFatalsUsingApply(): Unit = { fatals foreach { t => assert(NonFatal(t) == false) } diff --git a/test/files/jvm/nooptimise/Foo_1.flags b/test/files/jvm/nooptimise/Foo_1.flags new file mode 100644 index 0000000000..9686c20775 --- /dev/null +++ b/test/files/jvm/nooptimise/Foo_1.flags @@ -0,0 +1 @@ +-optimise -Ynooptimise
\ No newline at end of file diff --git a/test/files/jvm/nooptimise/Foo_1.scala b/test/files/jvm/nooptimise/Foo_1.scala new file mode 100644 index 0000000000..c6f1b06c8e --- /dev/null +++ b/test/files/jvm/nooptimise/Foo_1.scala @@ -0,0 +1,8 @@ +class Foo_1 { + def foo() { + // optimization will remove this magic 3 from appearing in the source + // so -Ynooptimize should prevent that + val x = 3 + + } +} diff --git a/test/files/jvm/nooptimise/Test.scala b/test/files/jvm/nooptimise/Test.scala new file mode 100644 index 0000000000..ec8daa6e16 --- /dev/null +++ b/test/files/jvm/nooptimise/Test.scala @@ -0,0 +1,23 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + // if optimization didn't run then + // there should be some useless instructions + // with the magic constant 3 + val expected = 1 + val got = countMagicThrees(methodNode.instructions) + assert(got == expected, s"expected $expected but got $got magic threes") + } + + def countMagicThrees(insnList: InsnList): Int = { + def isMagicThree(node: asm.tree.AbstractInsnNode): Boolean = + (node.getOpcode == asm.Opcodes.ICONST_3) + insnList.iterator.asScala.count(isMagicThree) + } +} diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala index 34b64938b4..f2c47aad77 100644 --- a/test/files/jvm/serialization.scala +++ b/test/files/jvm/serialization.scala @@ -604,6 +604,7 @@ object Test { Test7 Test8 Test9_parallel + Test10_util } } @@ -669,3 +670,17 @@ object Test9_parallel { throw e } } + +//############################################################################ +// Test classes in package scala.util + +object Test10_util { + import scala.util.Random + def rep[A](n: Int)(f: => A) { if (n > 0) { f; rep(n-1)(f) } } + + try { + val random = new Random(345) + val random2: Random = read(write(random)) + rep(5) { assert(random.nextInt == random2.nextInt) } + } +} diff --git a/test/files/jvm/t1143-2/t1143-2.scala b/test/files/jvm/t1143-2/t1143-2.scala index 44b1febd8b..13ab13b48c 100644 --- a/test/files/jvm/t1143-2/t1143-2.scala +++ b/test/files/jvm/t1143-2/t1143-2.scala @@ -16,43 +16,39 @@ object Serialize { } } -@serializable @SerialVersionUID(1L) -class VarModel[T]( getter: => T, setter: T => Unit ) -{ +class VarModel[T](getter: => T, setter: T => Unit) extends Serializable { Serialize.write(getter) Serialize.write(setter) - def this( getter: => T ) = this( getter, null ) + def this(getter: => T) = this(getter, null) def getObject: AnyRef = getter.asInstanceOf[AnyRef] - def setObject( v: AnyRef ) = { - if( setter==null ) - throw new RuntimeException( "Tried to set readonly model!") - setter( v.asInstanceOf[T] ) + def setObject(v: AnyRef) = { + if(setter==null) + throw new RuntimeException("Tried to set readonly model!") + setter(v.asInstanceOf[T]) } def detach = () } -@serializable @SerialVersionUID(1L) -class Printer( p: VarModel[String] ) { - def print = println( p.getObject ); +class Printer(p: VarModel[String]) extends Serializable { + def print = println(p.getObject) } class Component extends Marker { } class Form extends Component { } -@serializable @SerialVersionUID(1L) -class Main { +class Main extends Serializable { var pass = "pass" - def main(args : Array[String]) : Unit = { + def main(args: Array[String]): Unit = { val f = new Form { - val p = new Printer( new VarModel( pass, s => pass = s ) ); + val p = new Printer(new VarModel(pass, s => pass = s)) p.print } () diff --git a/test/files/jvm/t1143.scala b/test/files/jvm/t1143.scala index 7dd374f432..eb03c7224e 100644 --- a/test/files/jvm/t1143.scala +++ b/test/files/jvm/t1143.scala @@ -16,9 +16,8 @@ object Serialize { } } -@serializable @SerialVersionUID(1L) -class VarModel[T](getter: => T, setter: T => Unit) { +class VarModel[T](getter: => T, setter: T => Unit) extends Serializable { Serialize.write(getter) Serialize.write(setter) @@ -35,23 +34,20 @@ class VarModel[T](getter: => T, setter: T => Unit) { def detach = () } -@serializable @SerialVersionUID(1L) -class Printer(p: VarModel[String]) { +class Printer(p: VarModel[String]) extends Serializable { def print = println(p.getObject) } -@serializable @SerialVersionUID(1L) -class Component { +class Component extends Serializable { } class Form extends Component { } -@serializable @SerialVersionUID(1L) -class Main { +class Main extends Serializable { var pass = "pass" def main(args: Array[String]) { val f = new Form { diff --git a/test/files/jvm/t1342/SI.scala b/test/files/jvm/t1342/SI.scala index 8e3b753210..7c37d4bcd7 100644 --- a/test/files/jvm/t1342/SI.scala +++ b/test/files/jvm/t1342/SI.scala @@ -4,7 +4,7 @@ class SI extends JI { } } -object Test extends Application { +object Test extends App { val x: JI = new SI x.varArgsMethod("one", "two") } diff --git a/test/files/jvm/t1600.scala b/test/files/jvm/t1600.scala index 7e23687425..69179c1ba4 100644 --- a/test/files/jvm/t1600.scala +++ b/test/files/jvm/t1600.scala @@ -69,8 +69,7 @@ object Test { var hashCodeModifier = 0 } - @serializable - class Foo { + class Foo extends Serializable { override def hashCode = System.identityHashCode(this) + Foo.hashCodeModifier } } diff --git a/test/files/jvm/ticket2163/ticket2163.java b/test/files/jvm/t2163/t2163.java index b6511d241c..83bd37d212 100644 --- a/test/files/jvm/ticket2163/ticket2163.java +++ b/test/files/jvm/t2163/t2163.java @@ -1,9 +1,9 @@ import java.util.*; -public class ticket2163 { +public class t2163 { public void test() { List<Integer> array = new ArrayList<Integer>(); - Ticket2163Scala<List> foo = new Ticket2163Scala<List>(array); + T2163Scala<List> foo = new T2163Scala<List>(array); foo.bar(array); } } diff --git a/test/files/jvm/t2163/t2163.scala b/test/files/jvm/t2163/t2163.scala new file mode 100644 index 0000000000..f73b520cbe --- /dev/null +++ b/test/files/jvm/t2163/t2163.scala @@ -0,0 +1,5 @@ +class T2163Scala[CC[X]](x: CC[Int]) { + def bar[DD[X]](meh: DD[Int]): CC[Int] = x +} + +object Test extends App {} diff --git a/test/files/jvm/t2470.cmds b/test/files/jvm/t2470.cmds deleted file mode 100644 index b4ef0f4aeb..0000000000 --- a/test/files/jvm/t2470.cmds +++ /dev/null @@ -1,3 +0,0 @@ -javac Action.java Task.java -scalac Test_1.scala -scalac Read_Classfile_2.scala diff --git a/test/files/jvm/t2570/Test.scala b/test/files/jvm/t2570/Test.scala index 7944aedae6..f1cba53546 100644 --- a/test/files/jvm/t2570/Test.scala +++ b/test/files/jvm/t2570/Test.scala @@ -1,3 +1,3 @@ class Test2 extends Test1[Test3[Test4]] class Test4 -object Test extends Application {}
\ No newline at end of file +object Test extends App {}
\ No newline at end of file diff --git a/test/files/jvm/t3003.cmds b/test/files/jvm/t3003.cmds deleted file mode 100644 index c00396627c..0000000000 --- a/test/files/jvm/t3003.cmds +++ /dev/null @@ -1,2 +0,0 @@ -javac Annot.java -scalac Test_1.scala diff --git a/test/files/jvm/t3415/HelloWorld.scala b/test/files/jvm/t3415/HelloWorld.scala index 53bf55e444..5ef012390e 100644 --- a/test/files/jvm/t3415/HelloWorld.scala +++ b/test/files/jvm/t3415/HelloWorld.scala @@ -1,4 +1,4 @@ -object Test extends Application { +object Test extends App { @Hello def foo() { } } diff --git a/test/files/jvm/ticket4283/AbstractFoo.java b/test/files/jvm/t4283/AbstractFoo.java index 74f3827fe3..74f3827fe3 100644 --- a/test/files/jvm/ticket4283/AbstractFoo.java +++ b/test/files/jvm/t4283/AbstractFoo.java diff --git a/test/files/jvm/ticket4283/ScalaBipp.scala b/test/files/jvm/t4283/ScalaBipp.scala index 36dea9f4de..36dea9f4de 100644 --- a/test/files/jvm/ticket4283/ScalaBipp.scala +++ b/test/files/jvm/t4283/ScalaBipp.scala diff --git a/test/files/jvm/ticket4283/Test.scala b/test/files/jvm/t4283/Test.scala index 9bbfaab928..9bbfaab928 100644 --- a/test/files/jvm/ticket4283/Test.scala +++ b/test/files/jvm/t4283/Test.scala diff --git a/test/files/jvm/t7006/Foo_1.flags b/test/files/jvm/t7006/Foo_1.flags new file mode 100644 index 0000000000..37b2116413 --- /dev/null +++ b/test/files/jvm/t7006/Foo_1.flags @@ -0,0 +1 @@ +-optimise -Ydebug -Xfatal-warnings diff --git a/test/files/jvm/t7006/Foo_1.scala b/test/files/jvm/t7006/Foo_1.scala new file mode 100644 index 0000000000..995619ce6b --- /dev/null +++ b/test/files/jvm/t7006/Foo_1.scala @@ -0,0 +1,10 @@ +class Foo_1 { + def foo { + try { + val x = 3 // this will be optimized away, leaving a useless jump only block + } finally { + print("hello") + } + while(true){} // ensure infinite loop doesn't break the algoirthm + } +} diff --git a/test/files/jvm/t7006/Test.scala b/test/files/jvm/t7006/Test.scala new file mode 100644 index 0000000000..065a23510e --- /dev/null +++ b/test/files/jvm/t7006/Test.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + assert(count(methodNode.instructions, asm.Opcodes.NOP) == 0) + assert(count(methodNode.instructions, asm.Opcodes.GOTO) == 1) + } + + def count(insnList: InsnList, opcode: Int): Int = { + def isNop(node: asm.tree.AbstractInsnNode): Boolean = + (node.getOpcode == opcode) + insnList.iterator.asScala.count(isNop) + } +} diff --git a/test/files/jvm/t7181/Foo_1.scala b/test/files/jvm/t7181/Foo_1.scala new file mode 100644 index 0000000000..f9dfdd4442 --- /dev/null +++ b/test/files/jvm/t7181/Foo_1.scala @@ -0,0 +1,26 @@ +class Exception1 extends RuntimeException +class Exception2 extends RuntimeException + +class Foo_1 { + def foo(baz: Baz) { + try { + baz.bar + } catch { + case _: Exception1 => println("exception 1") + case _: Exception2 => println("exception 2") + } finally { + // this should be the only copy of the magic constant 3 + // making it easy to detect copies of this finally block + println(s"finally ${3}") + } + println(s"normal flow") + } +} + +trait Baz { + // does it throw? who knows? This way + // I can ensure that no optimization that honors + // separate compilation could ever + // change the exception handling structure + def bar: Unit +} diff --git a/test/files/jvm/t7181/Test.scala b/test/files/jvm/t7181/Test.scala new file mode 100644 index 0000000000..35dba436c1 --- /dev/null +++ b/test/files/jvm/t7181/Test.scala @@ -0,0 +1,24 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + // there should be 2 copies of the finally block, each with the magic constant 3 + // one for the "normal" exit + // one for the uncaught exception exit + // prior to this PR there would have been 4 since each exception handler would also get a copy + val expected = 2 + val got = countMagicThrees(methodNode.instructions) + assert(got == expected, s"expected $expected but got $got magic threes") + } + + def countMagicThrees(insnList: InsnList): Int = { + def isMagicThree(node: asm.tree.AbstractInsnNode): Boolean = + (node.getOpcode == asm.Opcodes.ICONST_3) + insnList.iterator.asScala.count(isMagicThree) + } +} diff --git a/test/files/jvm/ticket2163/ticket2163.scala b/test/files/jvm/ticket2163/ticket2163.scala deleted file mode 100644 index d30bfe251b..0000000000 --- a/test/files/jvm/ticket2163/ticket2163.scala +++ /dev/null @@ -1,5 +0,0 @@ -class Ticket2163Scala[CC[X]](x: CC[Int]) { - def bar[DD[X]](meh: DD[Int]): CC[Int] = x -} - -object Test extends Application {} diff --git a/test/files/jvm/typerep.scala b/test/files/jvm/typerep.scala index 3befc7ff3f..47bd16a467 100644 --- a/test/files/jvm/typerep.scala +++ b/test/files/jvm/typerep.scala @@ -280,100 +280,74 @@ object TypeRep { override def toString = "Nothing" } - @serializable case class ClassRep[A](elemRep: TypeRep[A]) extends TypeRep[Class[A]] { override def toString = "Class[" + elemRep + "]" } - @serializable case class SomeRep[A](elemRep: TypeRep[A]) extends TypeRep[Some[A]] { override def toString = "Some[" + elemRep + "]" } - @serializable case class NoneRep[A](elemRep: TypeRep[A]) extends TypeRep[Option[A]] { override def toString = "None[" + elemRep + "]" } - - @serializable case class ListRep[A](elemRep: TypeRep[A]) extends TypeRep[List[A]] { override def toString = "List[" + elemRep + "]" } - - @serializable case class ArrayRep[A](elemRep: TypeRep[A]) extends TypeRep[Array[A]] { override def toString = "Array[" + elemRep + "]" } - - @serializable case class Tuple2Rep[A1, A2](_1: TypeRep[A1], _2: TypeRep[A2]) extends TypeRep[(A1, A2)] { override def toString = "Tuple2[" + _1 + ", " + _2 + "]" } - @serializable case class Tuple3Rep[A1, A2, A3](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]) extends TypeRep[Tuple3[A1, A2, A3]] { override def toString = "Tuple3[" + _1 + ", " + _2 + ", " + _3 + "]" } - @serializable case class Tuple4Rep[A1, A2, A3, A4](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]) extends TypeRep[Tuple4[A1, A2, A3, A4]] { override def toString = "Tuple4[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + "]" } - @serializable case class Tuple5Rep[A1, A2, A3, A4, A5](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]) extends TypeRep[Tuple5[A1, A2, A3, A4, A5]] { override def toString = "Tuple5[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + "]" } - @serializable case class Tuple6Rep[A1, A2, A3, A4, A5, A6](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6]) extends TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] { override def toString = "Tuple6[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + "]" } - @serializable case class Tuple7Rep[A1, A2, A3, A4, A5, A6, A7](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7]) extends TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] { override def toString = "Tuple7[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + "]" } - @serializable case class Tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8]) extends TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] { override def toString = "Tuple8[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + "]" } - @serializable case class Tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8], val _9: TypeRep[A9]) extends TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] { override def toString = "Tuple9[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + "]" } - @serializable case class Function1Rep[A1, B](a1: TypeRep[A1], b: TypeRep[B]) extends TypeRep[Function1[A1, B]] { override def toString = "Function1[" + a1 + ", " + b + "]" } - @serializable case class Function2Rep[A1, A2, B](a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]) extends TypeRep[Function2[A1, A2, B]] { override def toString = "Function2[" + a1 + ", " + a2 + ", " + b + "]" } - @serializable case class Function3Rep[A1, A2, A3, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]) extends TypeRep[Function3[A1, A2, A3, B]] { override def toString = "Function3[" + a1 + ", " + a2 + ", " + a3 + ", " + b + "]" } - @serializable case class Function4Rep[A1, A2, A3, A4, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]) extends TypeRep[Function4[A1, A2, A3, A4, B]] { override def toString = "Function4[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + b + "]" } - @serializable case class Function5Rep[A1, A2, A3, A4, A5, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]) extends TypeRep[Function5[A1, A2, A3, A4, A5, B]] { override def toString = "Function5[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + b + "]" } - @serializable case class Function6Rep[A1, A2, A3, A4, A5, A6, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]) extends TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] { override def toString = "Function6[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + b + "]" } - @serializable case class Function7Rep[A1, A2, A3, A4, A5, A6, A7, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]) extends TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] { override def toString = "Function7[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + b + "]" } - @serializable case class Function8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]) extends TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] { override def toString = "Function8[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + b + "]" } - @serializable case class Function9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]) extends TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] { override def toString = "Function9[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + ", " + b + "]" } /* - @serializable case class ObjectRep[A](c: Class) extends TypeRep[A] { override def toString = c.getName } diff --git a/test/files/jvm/unreachable/Foo_1.flags b/test/files/jvm/unreachable/Foo_1.flags new file mode 100644 index 0000000000..ce6e93b3da --- /dev/null +++ b/test/files/jvm/unreachable/Foo_1.flags @@ -0,0 +1 @@ +-Ynooptimise
\ No newline at end of file diff --git a/test/files/jvm/unreachable/Foo_1.scala b/test/files/jvm/unreachable/Foo_1.scala new file mode 100644 index 0000000000..d17421c516 --- /dev/null +++ b/test/files/jvm/unreachable/Foo_1.scala @@ -0,0 +1,110 @@ +class Foo_1 { + def unreachableNormalExit: Int = { + return 42 + 0 + } + + def unreachableIf: Int = { + return 42 + if (util.Random.nextInt % 2 == 0) + 0 + else + 1 + } + + def unreachableIfBranches: Int = { + if (util.Random.nextInt % 2 == 0) + return 42 + else + return 42 + + return 0 + } + + def unreachableOneLegIf: Int = { + if (util.Random.nextInt % 2 == 0) + return 42 + + return 42 + } + + def unreachableLeftBranch: Int = { + val result = if (util.Random.nextInt % 2 == 0) + return 42 + else + 42 + + return result + } + + def unreachableRightBranch: Int = { + val result = if (util.Random.nextInt % 2 == 0) + 42 + else + return 42 + + return result + } + + def unreachableTryCatchFinally: Int = { + return 42 + try { + return 0 + } catch { + case x: Throwable => return 1 + } finally { + return 2 + } + return 3 + } + + def unreachableAfterTry: Int = { + try { + return 42 + } catch { + case x: Throwable => return 2 + } + return 3 + } + + def unreachableAfterCatch: Int = { + try { + error("haha") + } catch { + case x: Throwable => return 42 + } + return 3 + } + + def unreachableAfterFinally: Int = { + try { + return 1 + } catch { + case x: Throwable => return 2 + } finally { + return 42 + } + return 3 + } + + def unreachableSwitch: Int = { + return 42 + val x = util.Random.nextInt % 2 + x match { + case 0 => return 0 + case 1 => return 1 + case _ => error("wtf") + } + 2 + } + + def unreachableAfterSwitch: Int = { + val x = util.Random.nextInt % 2 + x match { + case 0 => return 42 + case 1 => return 41 + x + case _ => error("wtf") + } + 2 + } +}
\ No newline at end of file diff --git a/test/files/jvm/unreachable/Test.scala b/test/files/jvm/unreachable/Test.scala new file mode 100644 index 0000000000..3f520eb106 --- /dev/null +++ b/test/files/jvm/unreachable/Test.scala @@ -0,0 +1,23 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + // Foo_1 is full of unreachable code which if not elimintated + // will result in NOPs as can be confirmed by adding -Ydisable-unreachable-prevention + // to Foo_1.flags + for (methodNode <- classNode.methods.asScala) { + val got = count(methodNode.instructions, asm.Opcodes.NOP) + if (got != 0) println(s"Found $got NOP(s) in ${methodNode.name}") + } + } + + def count(insnList: InsnList, opcode: Int): Int = { + def isNop(node: asm.tree.AbstractInsnNode): Boolean = + (node.getOpcode == opcode) + insnList.iterator.asScala.count(isNop) + } +}
\ No newline at end of file diff --git a/test/files/jvm/value-class-boxing.check b/test/files/jvm/value-class-boxing.check new file mode 100644 index 0000000000..20a9fe2ba8 --- /dev/null +++ b/test/files/jvm/value-class-boxing.check @@ -0,0 +1,7 @@ +a2 and a1: bytecode identical +a3 and a1: bytecode identical +a4 and a1: bytecode identical +b2 and b1: bytecode identical +b3 and b1: bytecode identical +b4 and b1: bytecode identical +b5 and b1: bytecode identical diff --git a/test/files/jvm/value-class-boxing/Analyzed_1.scala b/test/files/jvm/value-class-boxing/Analyzed_1.scala new file mode 100644 index 0000000000..dec8565351 --- /dev/null +++ b/test/files/jvm/value-class-boxing/Analyzed_1.scala @@ -0,0 +1,17 @@ +class Wrap(val x: Int) extends AnyVal { + def ***(other: Bip): Wrap = new Wrap(x * other.x) +} +class Bip(val x: Int) extends AnyVal + +class SameBytecode { + def a1(x: Int, y: Int): Int = x + y + def a2(x: Wrap, y: Wrap): Wrap = new Wrap(x.x + y.x) + def a3(x: Int, y: Wrap): Wrap = new Wrap(x + y.x) + def a4(x: Int, y: Wrap): Int = x + y.x + + def b1(x: Wrap, y: Int): Int = (x *** new Bip(y)).x + def b2(x: Wrap, y: Bip): Wrap = x *** y + def b3(x: Wrap, y: Int): Wrap = x *** new Bip(y) + def b4(x: Wrap, y: Bip): Bip = new Bip((x *** y).x) + def b5(x: Wrap, y: Int): Bip = new Bip((x *** new Bip(y)).x) +} diff --git a/test/files/jvm/value-class-boxing/test.scala b/test/files/jvm/value-class-boxing/test.scala new file mode 100644 index 0000000000..cf331832de --- /dev/null +++ b/test/files/jvm/value-class-boxing/test.scala @@ -0,0 +1,15 @@ +import scala.tools.partest.BytecodeTest + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("SameBytecode") + List("a2", "a3", "a4") foreach { m => + print(m + " and a1: ") + sameBytecode(getMethod(classNode, "a1"), getMethod(classNode, m)) + } + List("b2", "b3", "b4", "b5") foreach { m => + print(m + " and b1: ") + sameBytecode(getMethod(classNode, "b1"), getMethod(classNode, m)) + } + } +} diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index 2fab650637..75777a5b94 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -1,7 +1,6 @@ import java.io.StringReader import org.xml.sax.InputSource -import scala.util.logging._ import scala.xml._ object Test extends App { diff --git a/test/files/jvm/xmlattr.scala b/test/files/jvm/xmlattr.scala index d214642eb6..6423268ba7 100644 --- a/test/files/jvm/xmlattr.scala +++ b/test/files/jvm/xmlattr.scala @@ -6,6 +6,7 @@ object Test { UnprefixedAttributeTest() AttributeWithOptionTest() AttributeOutputTest() + AttributeOperatorTest() } object UnprefixedAttributeTest { @@ -60,4 +61,10 @@ object Test { } } + object AttributeOperatorTest { + def apply() { + val xml = <foo bar="apple" /> + assert(xml \@ "bar" == "apple") + } + } } |