diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/icode-reader-dead-code.check | 19 | ||||
-rw-r--r-- | test/files/run/icode-reader-dead-code.scala | 82 | ||||
-rw-r--r-- | test/files/run/repl-javap-app.check | 39 | ||||
-rw-r--r-- | test/files/run/repl-javap-app.scala | 11 | ||||
-rw-r--r-- | test/files/run/t5905-features.scala | 8 | ||||
-rw-r--r-- | test/files/run/t7974.check | 29 | ||||
-rw-r--r-- | test/files/run/t7974/Test.scala | 2 | ||||
-rw-r--r-- | test/files/run/t8611a.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8611a.scala | 16 | ||||
-rw-r--r-- | test/files/run/t8611b.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8611b.scala | 54 | ||||
-rw-r--r-- | test/files/run/t8611c.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8611c.scala | 21 | ||||
-rw-r--r-- | test/files/run/t8637.check | 0 | ||||
-rw-r--r-- | test/files/run/t8637.scala | 9 |
15 files changed, 253 insertions, 40 deletions
diff --git a/test/files/run/icode-reader-dead-code.check b/test/files/run/icode-reader-dead-code.check new file mode 100644 index 0000000000..d1739fed3b --- /dev/null +++ b/test/files/run/icode-reader-dead-code.check @@ -0,0 +1,19 @@ +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + ATHROW + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 diff --git a/test/files/run/icode-reader-dead-code.scala b/test/files/run/icode-reader-dead-code.scala new file mode 100644 index 0000000000..00ba58829f --- /dev/null +++ b/test/files/run/icode-reader-dead-code.scala @@ -0,0 +1,82 @@ +import java.io.{FileOutputStream, FileInputStream} + +import scala.tools.asm.{ClassWriter, Opcodes, ClassReader} +import scala.tools.asm.tree.{InsnNode, ClassNode} +import scala.tools.nsc.backend.jvm.AsmUtils +import scala.tools.partest.DirectTest +import scala.collection.JavaConverters._ + +/** + * Test that the ICodeReader does not crash if the bytecode of a method has unreachable code. + */ +object Test extends DirectTest { + def code: String = ??? + + def show(): Unit = { + // The bytecode of f will be modified using ASM by `addDeadCode` + val aCode = + """ + |package p + |class A { + | @inline final def f = 1 + |} + """.stripMargin + + val bCode = + """ + |package p + |class B { + | def g = (new A()).f + |} + """.stripMargin + + compileString(newCompiler("-usejavacp"))(aCode) + + addDeadCode() + + // If inlining fails, the compiler will issue an inliner warning that is not present in the + // check file + compileString(newCompiler("-usejavacp", "-optimise"))(bCode) + } + + def readClass(file: String) = { + val cnode = new ClassNode() + val is = new FileInputStream(file) + val reader = new ClassReader(is) + reader.accept(cnode, 0) + is.close() + cnode + } + + def writeClass(file: String, cnode: ClassNode): Unit = { + val writer = new ClassWriter(0) + cnode.accept(writer) + + val os = new FileOutputStream(file) + os.write(writer.toByteArray) + os.close() + } + + def addDeadCode() { + val file = (testOutput / "p" / "A.class").path + val cnode = readClass(file) + val method = cnode.methods.asScala.find(_.name == "f").head + + AsmUtils.traceMethod(method) + + val insns = method.instructions + val it = insns.iterator() + while (it.hasNext) { + val in = it.next() + if (in.getOpcode == Opcodes.IRETURN) { + // Insert an ATHROW before the IRETURN. The IRETURN will then be dead code. + // The ICodeReader should not crash if there's dead code. + insns.insert(in.getPrevious, new InsnNode(Opcodes.ATHROW)) + } + } + + AsmUtils.traceMethod(method) + + writeClass(file, cnode) + } +} diff --git a/test/files/run/repl-javap-app.check b/test/files/run/repl-javap-app.check index 490860585c..1136b415d7 100644 --- a/test/files/run/repl-javap-app.check +++ b/test/files/run/repl-javap-app.check @@ -1,4 +1,5 @@ #partest java6 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -6,16 +7,17 @@ scala> :javap -app MyApp$ public final void delayedEndpoint$MyApp$1(); Code: Stack=2, Locals=1, Args_size=1 - 0: getstatic #61; //Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63; //String Hello, delayed world. - 5: invokevirtual #67; //Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX; //Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX; //String Hello, delayed world. + 5: invokevirtual #XX; //Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature 0 9 0 this LMyApp$; scala> -#partest !java6 +#partest java7 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -24,9 +26,9 @@ scala> :javap -app MyApp$ flags: ACC_PUBLIC, ACC_FINAL Code: stack=2, locals=1, args_size=1 - 0: getstatic #61 // Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63 // String Hello, delayed world. - 5: invokevirtual #67 // Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX // String Hello, delayed world. + 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature @@ -36,3 +38,26 @@ scala> :javap -app MyApp$ } scala> +#partest java8 +Welcome to Scala +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :javap -app MyApp$ + public final void delayedEndpoint$MyApp$1(); + descriptor: ()V + flags: ACC_PUBLIC, ACC_FINAL + Code: + stack=2, locals=1, args_size=1 + 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX // String Hello, delayed world. + 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V + 8: return + LocalVariableTable: + Start Length Slot Name Signature + 0 9 0 this LMyApp$; + LineNumberTable: + line 5: 0 +} + +scala> diff --git a/test/files/run/repl-javap-app.scala b/test/files/run/repl-javap-app.scala index be04920be1..ad6076c2d5 100644 --- a/test/files/run/repl-javap-app.scala +++ b/test/files/run/repl-javap-app.scala @@ -7,4 +7,15 @@ object MyApp extends App { object Test extends ReplTest { def code = ":javap -app MyApp$" + + override def welcoming = true + + // The constant pool indices are not the same for GenASM / GenBCode, so + // replacing the exact numbers by XX. + lazy val hasConstantPoolRef = """(.*)(#\d\d)(.*)""".r + + override def normalize(s: String) = s match { + case hasConstantPoolRef(start, ref, end) => start + "#XX" + end + case _ => super.normalize(s) + } } diff --git a/test/files/run/t5905-features.scala b/test/files/run/t5905-features.scala index a3848eef2a..b518d61145 100644 --- a/test/files/run/t5905-features.scala +++ b/test/files/run/t5905-features.scala @@ -3,13 +3,13 @@ import tools.partest.DirectTest // verify that all languageFeature names are accepted by -language object Test extends DirectTest { - override def code = "class Code { def f = (1 to 10) size }" // exercise a feature + override def code = "class Code { def f = (1 to 10) size }" // exercise a feature to sanity-check coverage of -language options override def extraSettings = s"-usejavacp -d ${testOutput.path}" override def show() = { - val global = newCompiler("-language:postfixOps", "-Ystop-after:typer") - compileString(global)(code) + val global = newCompiler("-Ystop-after:typer") + compileString(global)("") // warm me up, scotty import global._ exitingTyper { //def isFeature(s: Symbol) = s.annotations.exists((a: AnnotationInfo) => a.tpe <:< typeOf[scala.annotation.meta.languageFeature]) @@ -21,6 +21,8 @@ object Test extends DirectTest { assert(feats.nonEmpty, "Test must find feature flags.") + //compile("junk") // tragically, does not fail the test, i.e., arg must not be totally borked + //dynamics,postfixOps,reflectiveCalls,implicitConversions,higherKinds,existentials,experimental.macros compile(s"-language:$all") } diff --git a/test/files/run/t7974.check b/test/files/run/t7974.check index 0be496d8d0..d8152d3286 100644 --- a/test/files/run/t7974.check +++ b/test/files/run/t7974.check @@ -1,6 +1,5 @@ public class Symbols { - // compiled from: Symbols.scala @@ -18,20 +17,14 @@ public class Symbols { // access flags 0x9 public static <clinit>()V - L0 - LINENUMBER 2 L0 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic1" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$1 : Lscala/Symbol; - L1 - LINENUMBER 3 L1 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic2" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$2 : Lscala/Symbol; - L2 - LINENUMBER 5 L2 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic3" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; @@ -42,63 +35,41 @@ public class Symbols { // access flags 0x1 public someSymbol1()Lscala/Symbol; - L0 - LINENUMBER 2 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol2()Lscala/Symbol; - L0 - LINENUMBER 3 L0 GETSTATIC Symbols.symbol$2 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public sameSymbol1()Lscala/Symbol; - L0 - LINENUMBER 4 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol3()Lscala/Symbol; - L0 - LINENUMBER 5 L0 ALOAD 0 GETFIELD Symbols.someSymbol3 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public <init>()V - L0 - LINENUMBER 6 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V - L1 - LINENUMBER 5 L1 ALOAD 0 GETSTATIC Symbols.symbol$3 : Lscala/Symbol; PUTFIELD Symbols.someSymbol3 : Lscala/Symbol; RETURN - L2 - LOCALVARIABLE this LSymbols; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 } diff --git a/test/files/run/t7974/Test.scala b/test/files/run/t7974/Test.scala index 433d9061a7..29d2b9cb64 100644 --- a/test/files/run/t7974/Test.scala +++ b/test/files/run/t7974/Test.scala @@ -6,7 +6,7 @@ import scala.tools.nsc.util.stringFromWriter object Test extends BytecodeTest { def show { - val classNode = loadClassNode("Symbols", skipDebugInfo = false) + val classNode = loadClassNode("Symbols", skipDebugInfo = true) val textifier = new Textifier classNode.accept(new TraceClassVisitor(null, textifier, null)) diff --git a/test/files/run/t8611a.flags b/test/files/run/t8611a.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/run/t8611a.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/run/t8611a.scala b/test/files/run/t8611a.scala new file mode 100644 index 0000000000..99304df762 --- /dev/null +++ b/test/files/run/t8611a.scala @@ -0,0 +1,16 @@ +trait K +trait L + +object O { + type LK = K with L + val A: LK = new K with L + val B: LK = new K with L +} + +object Test extends App { + val scrut: O.LK = O.B + scrut match { + case O.A => ??? + case O.B => // spurious unreachable + } +} diff --git a/test/files/run/t8611b.flags b/test/files/run/t8611b.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/run/t8611b.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/run/t8611b.scala b/test/files/run/t8611b.scala new file mode 100644 index 0000000000..2df17c9ca0 --- /dev/null +++ b/test/files/run/t8611b.scala @@ -0,0 +1,54 @@ +sealed trait KrafsDescription + +abstract class NotWorkingEnum extends Enumeration { + + type ExtendedValue = Value with KrafsDescription + + def Enum(inDescription: String): ExtendedValue = { + new Val(nextId) with KrafsDescription { + } + } +} + +abstract class WorkingEnum extends Enumeration { + + type ExtendedValue = Value + + def Enum(inDescription: String): ExtendedValue = { + new Val(nextId) { + } + } +} + +object NotWorkingTab extends NotWorkingEnum { + val a = Enum("A") + val b = Enum("B") +} + +object WorkingTab extends WorkingEnum { + val a = Enum("A") + val b = Enum("B") +} + +object Test extends App { + testGris() + testWorking() + + def testGris() { + val pipp = NotWorkingTab.b + pipp match { + case NotWorkingTab.a => ??? + case NotWorkingTab.b => + case _ => ??? + } + } + + def testWorking() { + val stuff = WorkingTab.a + stuff match { + case WorkingTab.a => + case WorkingTab.b => ??? + case _ => ??? + } + } +} diff --git a/test/files/run/t8611c.flags b/test/files/run/t8611c.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/run/t8611c.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/run/t8611c.scala b/test/files/run/t8611c.scala new file mode 100644 index 0000000000..2bd17f29a5 --- /dev/null +++ b/test/files/run/t8611c.scala @@ -0,0 +1,21 @@ +trait K +trait L + +object O { + type LK = K with L +} + +object Test extends App { + local + + def local = { + val A: O.LK = new K with L + val B: O.LK = new K with L + val scrut: O.LK = A + scrut match { + case B if "".isEmpty => ??? + case A => + case B => ??? + } + } +} diff --git a/test/files/run/t8637.check b/test/files/run/t8637.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t8637.check diff --git a/test/files/run/t8637.scala b/test/files/run/t8637.scala new file mode 100644 index 0000000000..99c8d4c413 --- /dev/null +++ b/test/files/run/t8637.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.currentMirror +import scala.tools.reflect.ToolBox + +object Test extends App { + val tb = currentMirror.mkToolBox() + tb.compile(q"true > true") + tb.typecheck(q"true > true") +}
\ No newline at end of file |