summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/run/delambdafy_t6028.check4
-rw-r--r--test/junit/scala/issues/BytecodeTest.scala14
-rw-r--r--test/junit/scala/issues/OptimizedBytecodeTest.scala47
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala27
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala5
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala90
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala105
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala18
-rw-r--r--test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala59
-rw-r--r--test/scaladoc/run/SI-6017.scala28
-rw-r--r--test/scaladoc/run/SI-9620.scala1
-rw-r--r--test/scaladoc/run/shortDescription-annotation.check (renamed from test/scaladoc/run/SI-6017.check)0
-rw-r--r--test/scaladoc/run/shortDescription-annotation.scala55
-rw-r--r--test/scaladoc/scalacheck/DeprecatedIndexTest.scala4
-rw-r--r--test/scaladoc/scalacheck/HtmlFactoryTest.scala43
-rw-r--r--test/scaladoc/scalacheck/IndexTest.scala12
16 files changed, 269 insertions, 243 deletions
diff --git a/test/files/run/delambdafy_t6028.check b/test/files/run/delambdafy_t6028.check
index c8c4b1cb4c..b5a6e4b64e 100644
--- a/test/files/run/delambdafy_t6028.check
+++ b/test/files/run/delambdafy_t6028.check
@@ -11,7 +11,7 @@ package <empty> {
def foo(methodParam: String): Function0 = {
val methodLocal: String = "";
{
- (() => T.this.$anonfun$1(methodParam, methodLocal)).$asInstanceOf[Function0]()
+ (() => T.this.$anonfun$1(methodParam, methodLocal))
}
};
def bar(barParam: String): Object = {
@@ -21,7 +21,7 @@ package <empty> {
def tryy(tryyParam: String): Function0 = {
var tryyLocal: runtime.ObjectRef = scala.runtime.ObjectRef.create("");
{
- (() => T.this.$anonfun$2(tryyParam, tryyLocal)).$asInstanceOf[Function0]()
+ (() => T.this.$anonfun$2(tryyParam, tryyLocal))
}
};
final <artifact> private[this] def $anonfun$1(methodParam$1: String, methodLocal$1: String): String = T.this.classParam.+(T.this.field()).+(methodParam$1).+(methodLocal$1);
diff --git a/test/junit/scala/issues/BytecodeTest.scala b/test/junit/scala/issues/BytecodeTest.scala
index ca1b33ed20..18f8b44391 100644
--- a/test/junit/scala/issues/BytecodeTest.scala
+++ b/test/junit/scala/issues/BytecodeTest.scala
@@ -150,21 +150,21 @@ class BytecodeTest extends ClearAfterClass {
val List(c) = compileClasses(compiler)(code)
// t1: no unnecessary GOTOs
- assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(
+ assertSameCode(getSingleMethod(c, "t1"), List(
VarOp(ILOAD, 1), Jump(IFEQ, Label(6)),
Op(ICONST_1), Jump(GOTO, Label(9)),
Label(6), Op(ICONST_2),
Label(9), Op(IRETURN)))
// t2: no unnecessary GOTOs
- assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(
+ assertSameCode(getSingleMethod(c, "t2"), List(
VarOp(ILOAD, 1), IntOp(SIPUSH, 393), Jump(IF_ICMPNE, Label(7)),
Op(ICONST_1), Jump(GOTO, Label(10)),
Label(7), Op(ICONST_2),
Label(10), Op(IRETURN)))
// t3: Array == is translated to reference equality, AnyRef == to null checks and equals
- assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(
+ assertSameCode(getSingleMethod(c, "t3"), List(
// Array ==
VarOp(ALOAD, 1), VarOp(ALOAD, 2), Jump(IF_ACMPEQ, Label(23)),
// AnyRef ==
@@ -183,13 +183,13 @@ class BytecodeTest extends ClearAfterClass {
Label(13), Op(IRETURN))
// t4: one side is known null, so just a null check on the other
- assertSameCode(getSingleMethod(c, "t4").instructions.dropNonOp, t4t5)
+ assertSameCode(getSingleMethod(c, "t4"), t4t5)
// t5: one side known null, so just a null check on the other
- assertSameCode(getSingleMethod(c, "t5").instructions.dropNonOp, t4t5)
+ assertSameCode(getSingleMethod(c, "t5"), t4t5)
// t6: no unnecessary GOTOs
- assertSameCode(getSingleMethod(c, "t6").instructions.dropNonOp, List(
+ assertSameCode(getSingleMethod(c, "t6"), List(
VarOp(ILOAD, 1), IntOp(BIPUSH, 10), Jump(IF_ICMPNE, Label(7)),
VarOp(ILOAD, 2), Jump(IFNE, Label(12)),
Label(7), VarOp(ILOAD, 1), Op(ICONST_1), Jump(IF_ICMPEQ, Label(16)),
@@ -201,7 +201,7 @@ class BytecodeTest extends ClearAfterClass {
assertInvoke(getSingleMethod(c, "t7"), "scala/runtime/BoxesRunTime", "equals")
// t8: no null checks invoking equals on modules and constants
- assertSameCode(getSingleMethod(c, "t8").instructions.dropNonOp, List(
+ assertSameCode(getSingleMethod(c, "t8"), List(
Field(GETSTATIC, "scala/collection/immutable/Nil$", "MODULE$", "Lscala/collection/immutable/Nil$;"), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false), Jump(IFNE, Label(10)),
Ldc(LDC, ""), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false), Jump(IFNE, Label(14)),
Label(10), Op(ICONST_1), Jump(GOTO, Label(17)),
diff --git a/test/junit/scala/issues/OptimizedBytecodeTest.scala b/test/junit/scala/issues/OptimizedBytecodeTest.scala
index 0e1a52b1c8..1555e8945a 100644
--- a/test/junit/scala/issues/OptimizedBytecodeTest.scala
+++ b/test/junit/scala/issues/OptimizedBytecodeTest.scala
@@ -36,7 +36,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertSameCode(getSingleMethod(c, "t").instructions.dropNonOp, List(Label(0), Jump(GOTO, Label(0))))
+ assertSameCode(getSingleMethod(c, "t"), List(Label(0), Jump(GOTO, Label(0))))
}
@Test
@@ -55,17 +55,10 @@ class OptimizedBytecodeTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertEquals(
- getSingleMethod(c, "t").instructions.summary,
- List(LDC, ASTORE, ALOAD /*0*/, ALOAD /*1*/, "C$$$anonfun$1", IRETURN))
-
- assertEquals(
- getSingleMethod(c, "C$$$anonfun$1").instructions.summary,
- List(LDC, "C$$$anonfun$2", IRETURN))
-
- assertEquals(
- getSingleMethod(c, "C$$$anonfun$2").instructions.summary,
- List(-1 /*A*/, GOTO /*A*/))
+ assertSameSummary(getSingleMethod(c, "t"), List(
+ LDC, ASTORE, ALOAD /*0*/, ALOAD /*1*/, "C$$$anonfun$1", IRETURN))
+ assertSameSummary(getSingleMethod(c, "C$$$anonfun$1"), List(LDC, "C$$$anonfun$2", IRETURN))
+ assertSameSummary(getSingleMethod(c, "C$$$anonfun$2"), List(-1 /*A*/, GOTO /*A*/))
}
@Test
@@ -87,9 +80,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
val List(c, t, tMod) = compileClasses(compiler)(code, allowMessage = _.msg.contains("not be exhaustive"))
- assertEquals(
- getSingleMethod(c, "t").instructions.summary,
- List(GETSTATIC, "$qmark$qmark$qmark", ATHROW))
+ assertSameSummary(getSingleMethod(c, "t"), List(GETSTATIC, "$qmark$qmark$qmark", ATHROW))
}
@Test
@@ -235,9 +226,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertEquals(
- getSingleMethod(c, "t").instructions.summary,
- List(
+ assertSameSummary(getSingleMethod(c, "t"), List(
ALOAD /*1*/, INSTANCEOF /*Some*/, IFNE /*A*/,
ALOAD /*0*/, "getInt", POP,
-1 /*A*/, BIPUSH, IRETURN))
@@ -256,13 +245,11 @@ class OptimizedBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertEquals(
- getSingleMethod(c, "t").instructions.summary,
- List(
- -1 /*A*/, ILOAD /*1*/, TABLESWITCH,
- -1, ALOAD, "pr", RETURN,
- -1, ALOAD, "pr", RETURN,
- -1, ILOAD, ICONST_2, ISUB, ISTORE, GOTO /*A*/))
+ assertSameSummary(getSingleMethod(c, "t"), List(
+ -1 /*A*/, ILOAD /*1*/, TABLESWITCH,
+ -1, ALOAD, "pr", RETURN,
+ -1, ALOAD, "pr", RETURN,
+ -1, ILOAD, ICONST_2, ISUB, ISTORE, GOTO /*A*/))
}
@Test
@@ -283,12 +270,10 @@ class OptimizedBytecodeTest extends ClearAfterClass {
val cls = compileClassesSeparately(List(c1, c2), extraArgs = OptimizedBytecodeTest.args)
val c = cls.find(_.name == "C").get
- assertEquals(
- getSingleMethod(c, "t").instructions.summary,
- List(
- GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW, // module load and null checks not yet eliminated
- -1, ICONST_1, GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW,
- -1, ICONST_2, IADD, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t"), List(
+ GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW, // module load and null checks not yet eliminated
+ -1, ICONST_1, GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW,
+ -1, ICONST_2, IADD, IRETURN))
}
@Test
diff --git a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
index 0d353e930e..fe43ed2f6a 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
@@ -164,8 +164,18 @@ object CodeGenTools {
convertMethod(m)
}
+ def assertSameCode(method: Method, expected: List[Instruction]): Unit = assertSameCode(method.instructions.dropNonOp, expected)
def assertSameCode(actual: List[Instruction], expected: List[Instruction]): Unit = {
- assertTrue(s"\nExpected: $expected\nActual : $actual", actual === expected)
+ assert(actual === expected, s"\nExpected: $expected\nActual : $actual")
+ }
+
+ def assertSameSummary(method: Method, expected: List[Any]): Unit = assertSameSummary(method.instructions, expected)
+ def assertSameSummary(actual: List[Instruction], expected: List[Any]): Unit = {
+ def expectedString = expected.map({
+ case s: String => s""""$s""""
+ case i: Int => opcodeToString(i, i)
+ }).mkString("List(", ", ", ")")
+ assert(actual.summary == expected, s"\nFound : ${actual.summaryText}\nExpected: $expectedString")
}
def assertNoInvoke(m: Method): Unit = assertNoInvoke(m.instructions)
@@ -181,6 +191,21 @@ object CodeGenTools {
}, l.stringLines)
}
+ def assertDoesNotInvoke(m: Method, method: String): Unit = assertDoesNotInvoke(m.instructions, method)
+ def assertDoesNotInvoke(l: List[Instruction], method: String): Unit = {
+ assert(!l.exists {
+ case i: Invoke => i.name == method
+ case _ => false
+ }, l.stringLines)
+ }
+
+ def assertInvokedMethods(m: Method, expected: List[String]): Unit = assertInvokedMethods(m.instructions, expected)
+ def assertInvokedMethods(l: List[Instruction], expected: List[String]): Unit = {
+ def quote(l: List[String]) = l.map(s => s""""$s"""").mkString("List(", ", ", ")")
+ val actual = l collect { case i: Invoke => i.owner + "." + i.name }
+ assert(actual == expected, s"\nFound : ${quote(actual)}\nExpected: ${quote(expected)}")
+ }
+
def getSingleMethod(classNode: ClassNode, name: String): Method =
convertMethod(classNode.methods.asScala.toList.find(_.name == name).get)
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala
index b314643fb1..a0b9d6b4ed 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala
@@ -82,7 +82,7 @@ class ClosureOptimizerTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertSameCode(getSingleMethod(c, "t").instructions.dropNonOp,
+ assertSameCode(getSingleMethod(c, "t"),
List(VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "scala/collection/immutable/List", "head", "()Ljava/lang/Object;", false),
TypeOp(CHECKCAST, "java/lang/String"), Invoke(INVOKESTATIC, "C", "C$$$anonfun$1", "(Ljava/lang/String;)Ljava/lang/String;", false),
Op(ARETURN)))
@@ -103,7 +103,6 @@ class ClosureOptimizerTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(compiler)(code)
- assertEquals(getSingleMethod(c, "t").instructions.summary,
- List(NEW, DUP, LDC, "<init>", ATHROW))
+ assertSameSummary(getSingleMethod(c, "t"), List(NEW, DUP, LDC, "<init>", ATHROW))
}
}
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
index 54eddc868d..2c8f5e794e 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
@@ -100,7 +100,7 @@ class InlinerTest extends ClearAfterClass {
val g = inlineTest(code)
val gConv = convertMethod(g)
- assertSameCode(gConv.instructions.dropNonOp,
+ assertSameCode(gConv,
List(
VarOp(ALOAD, 0), VarOp(ASTORE, 1), // store this
Op(ICONST_1), VarOp(ISTORE, 2), Jump(GOTO, Label(10)), // store return value
@@ -144,10 +144,10 @@ class InlinerTest extends ClearAfterClass {
VarOp(ALOAD, 2),
Op(ATHROW))
- assertSameCode(convertMethod(g).instructions.dropNonOp, gBeforeLocalOpt)
+ assertSameCode(convertMethod(g), gBeforeLocalOpt)
compiler.genBCode.bTypes.localOpt.methodOptimizations(g, "C")
- assertSameCode(convertMethod(g).instructions.dropNonOp, invokeQQQ :+ Op(ATHROW))
+ assertSameCode(convertMethod(g), invokeQQQ :+ Op(ATHROW))
}
@Test
@@ -1313,60 +1313,40 @@ class InlinerTest extends ClearAfterClass {
""".stripMargin
val List(c, _, _) = compile(code)
- assertEquals(getSingleMethod(c, "t1").instructions.summary,
- List(BIPUSH, "C$$$anonfun$1", IRETURN))
-
- assertEquals(getSingleMethod(c, "t1a").instructions.summary,
- List(LCONST_1, "C$$$anonfun$2", IRETURN))
-
- assertEquals(getSingleMethod(c, "t2").instructions.summary, List(
- ICONST_1, ICONST_2, "C$$$anonfun$3",IRETURN))
+ assertSameSummary(getSingleMethod(c, "t1"), List(BIPUSH, "C$$$anonfun$1", IRETURN))
+ assertSameSummary(getSingleMethod(c, "t1a"), List(LCONST_1, "C$$$anonfun$2", IRETURN))
+ assertSameSummary(getSingleMethod(c, "t2"), List(ICONST_1, ICONST_2, "C$$$anonfun$3",IRETURN))
// val a = new ValKl(n); new ValKl(anonfun(a.x)).x
// value class instantiation-extraction should be optimized by boxing elim
- assertEquals(getSingleMethod(c, "t3").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t3"), List(
NEW, DUP, ICONST_1, "<init>", ASTORE,
NEW, DUP, ALOAD, "x",
"C$$$anonfun$4",
"<init>",
"x", IRETURN))
- assertEquals(getSingleMethod(c, "t4").instructions.summary, List(
- BIPUSH, "C$$$anonfun$5", "boxToInteger", ARETURN))
-
- assertEquals(getSingleMethod(c, "t4a").instructions.summary, List(
- ICONST_1, LDC, "C$$$anonfun$6", LRETURN))
-
- assertEquals(getSingleMethod(c, "t5").instructions.summary, List(
- BIPUSH, ICONST_3, "C$$$anonfun$7", "boxToInteger", ARETURN))
-
- assertEquals(getSingleMethod(c, "t5a").instructions.summary, List(
- BIPUSH, BIPUSH, I2B, "C$$$anonfun$8", IRETURN))
-
- assertEquals(getSingleMethod(c, "t6").instructions.summary, List(
- BIPUSH, "C$$$anonfun$9", RETURN))
-
- assertEquals(getSingleMethod(c, "t7").instructions.summary, List(
- ICONST_1, "C$$$anonfun$10", RETURN))
-
- assertEquals(getSingleMethod(c, "t8").instructions.summary, List(
- ICONST_1, LDC, "C$$$anonfun$11", LRETURN))
-
- assertEquals(getSingleMethod(c, "t9").instructions.summary, List(
- ICONST_1, "boxToInteger", "C$$$anonfun$12", RETURN))
+ assertSameSummary(getSingleMethod(c, "t4"), List(BIPUSH, "C$$$anonfun$5", "boxToInteger", ARETURN))
+ assertSameSummary(getSingleMethod(c, "t4a"), List(ICONST_1, LDC, "C$$$anonfun$6", LRETURN))
+ assertSameSummary(getSingleMethod(c, "t5"), List(BIPUSH, ICONST_3, "C$$$anonfun$7", "boxToInteger", ARETURN))
+ assertSameSummary(getSingleMethod(c, "t5a"), List(BIPUSH, BIPUSH, I2B, "C$$$anonfun$8", IRETURN))
+ assertSameSummary(getSingleMethod(c, "t6"), List(BIPUSH, "C$$$anonfun$9", RETURN))
+ assertSameSummary(getSingleMethod(c, "t7"), List(ICONST_1, "C$$$anonfun$10", RETURN))
+ assertSameSummary(getSingleMethod(c, "t8"), List(ICONST_1, LDC, "C$$$anonfun$11", LRETURN))
+ assertSameSummary(getSingleMethod(c, "t9"), List(ICONST_1, "boxToInteger", "C$$$anonfun$12", RETURN))
// t9a inlines Range.foreach, which is quite a bit of code, so just testing the core
assertInvoke(getSingleMethod(c, "t9a"), "C", "C$$$anonfun$13")
- assert(getSingleMethod(c, "t9a").instructions.summary.contains("boxToInteger"))
+ assertInvoke(getSingleMethod(c, "t9a"), "scala/runtime/BoxesRunTime", "boxToInteger")
- assertEquals(getSingleMethod(c, "t10").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t10"), List(
ICONST_1, ISTORE,
ALOAD, ILOAD,
"C$$$anonfun$14", RETURN))
// t10a inlines Range.foreach
assertInvoke(getSingleMethod(c, "t10a"), "C", "C$$$anonfun$15")
- assert(!getSingleMethod(c, "t10a").instructions.summary.contains("boxToInteger"))
+ assertDoesNotInvoke(getSingleMethod(c, "t10a"), "boxToInteger")
}
@Test
@@ -1389,7 +1369,7 @@ class InlinerTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compile(code)
- assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(Op(ICONST_0), Op(ICONST_1), Op(IADD), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t1"), List(Op(ICONST_0), Op(ICONST_1), Op(IADD), Op(IRETURN)))
assertEquals(getSingleMethod(c, "t2").instructions collect { case i: Invoke => i.owner +"."+ i.name }, List(
"scala/runtime/IntRef.create", "C.C$$$anonfun$1"))
}
@@ -1430,9 +1410,9 @@ class InlinerTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compile(code)
- assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(Op(ICONST_3), Op(ICONST_4), Op(IADD), Op(IRETURN)))
- assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(Op(ICONST_1), Op(ICONST_2), Op(IADD), Op(IRETURN)))
- assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(Op(ICONST_1), Op(ICONST_3), Op(ISUB), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t1"), List(Op(ICONST_3), Op(ICONST_4), Op(IADD), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t2"), List(Op(ICONST_1), Op(ICONST_2), Op(IADD), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t3"), List(Op(ICONST_1), Op(ICONST_3), Op(ISUB), Op(IRETURN)))
assertNoInvoke(getSingleMethod(c, "t4"))
assertNoInvoke(getSingleMethod(c, "t5"))
}
@@ -1461,9 +1441,9 @@ class InlinerTest extends ClearAfterClass {
""".stripMargin
val List(c, _) = compile(code)
def casts(m: String) = getSingleMethod(c, m).instructions collect { case TypeOp(CHECKCAST, tp) => tp }
- assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(VarOp(ALOAD, 1), Op(ARETURN)))
- assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(VarOp(ALOAD, 1), Op(ARETURN)))
- assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(VarOp(ALOAD, 1), TypeOp(CHECKCAST, "C"), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t1"), List(VarOp(ALOAD, 1), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t2"), List(VarOp(ALOAD, 1), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t3"), List(VarOp(ALOAD, 1), TypeOp(CHECKCAST, "C"), Op(ARETURN)))
assertEquals(casts("t4"), List("C"))
assertEquals(casts("t5"), Nil)
assertEquals(casts("t6"), Nil)
@@ -1489,12 +1469,11 @@ class InlinerTest extends ClearAfterClass {
val cls = compile(code)
val test = cls.find(_.name == "Test$").get
- assertEquals(
- getSingleMethod(test, "f").instructions.summary,
- List(GETSTATIC, "mkFoo",
- BIPUSH, ISTORE,
- IFNONNULL, ACONST_NULL, ATHROW, -1 /*label*/,
- ILOAD, ICONST_1, IADD, IRETURN))
+ assertSameSummary(getSingleMethod(test, "f"), List(
+ GETSTATIC, "mkFoo",
+ BIPUSH, ISTORE,
+ IFNONNULL, ACONST_NULL, ATHROW, -1 /*label*/,
+ ILOAD, ICONST_1, IADD, IRETURN))
}
@Test // a test taken from the test suite for the 2.11 inliner
@@ -1509,11 +1488,10 @@ class InlinerTest extends ClearAfterClass {
val List(c) = compile(code)
// box-unbox will clean it up
- assertEquals(getSingleMethod(c, "t").instructions.summary,
- List(
- ALOAD, "C$$$anonfun$1", IFEQ /*A*/,
- "C$$$anonfun$2", IRETURN,
- -1 /*A*/, "C$$$anonfun$3", IRETURN))
+ assertSameSummary(getSingleMethod(c, "t"), List(
+ ALOAD, "C$$$anonfun$1", IFEQ /*A*/,
+ "C$$$anonfun$2", IRETURN,
+ -1 /*A*/, "C$$$anonfun$3", IRETURN))
}
@Test
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
index 8f18a84a1c..0a9a26cda7 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
@@ -46,8 +46,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
val code = "def f = { try {} catch { case _: Throwable => 0 }; 1 }"
val m = singleMethod(methodOptCompiler)(code)
assertTrue(m.handlers.length == 0)
- assertSameCode(m.instructions.dropNonOp,
- List(Op(ICONST_1), Op(IRETURN)))
+ assertSameCode(m, List(Op(ICONST_1), Op(IRETURN)))
}
@Test
@@ -89,7 +88,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val m = singleMethod(methodOptCompiler)(code)
assertTrue(m.handlers.isEmpty)
- assertSameCode(m.instructions.dropNonOp, List(Op(ICONST_3), Op(IRETURN)))
+ assertSameCode(m, List(Op(ICONST_3), Op(IRETURN)))
}
@Test
@@ -108,8 +107,8 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertSameCode(getSingleMethod(c, "t").instructions.dropNonOp,
- List(Op(ACONST_NULL), Invoke(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(
+ Op(ACONST_NULL), Invoke(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false), Op(ARETURN)))
}
@Test
@@ -126,8 +125,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
assertSameCode(
- getSingleMethod(c, "t").instructions.dropNonOp,
- List(Ldc(LDC, "c"), Op(ARETURN)))
+ getSingleMethod(c, "t"), List(Ldc(LDC, "c"), Op(ARETURN)))
}
@Test
@@ -147,13 +145,11 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(
- getSingleMethod(c, "t").instructions.dropNonOp,
- List(
- Ldc(LDC, "el"), VarOp(ASTORE, 1),
- Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
- Op(ACONST_NULL), VarOp(ASTORE, 1),
- Ldc(LDC, "zit"), VarOp(ASTORE, 1), VarOp(ALOAD, 1), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(
+ Ldc(LDC, "el"), VarOp(ASTORE, 1),
+ Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
+ Op(ACONST_NULL), VarOp(ASTORE, 1),
+ Ldc(LDC, "zit"), VarOp(ASTORE, 1), VarOp(ALOAD, 1), Op(ARETURN)))
}
@Test
@@ -172,8 +168,8 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t").instructions.dropNonOp,
- List(IntOp(BIPUSH, 23), IntOp(NEWARRAY, 5), Op(POP), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(
+ IntOp(BIPUSH, 23), IntOp(NEWARRAY, 5), Op(POP), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
}
@Test
@@ -187,9 +183,9 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t").instructions.dropNonOp,
- List(TypeOp(NEW, "java/lang/Integer"), Ldc(LDC, "nono"), Invoke(INVOKESPECIAL, "java/lang/Integer", "<init>", "(Ljava/lang/String;)V", false),
- VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(
+ TypeOp(NEW, "java/lang/Integer"), Ldc(LDC, "nono"), Invoke(INVOKESPECIAL, "java/lang/Integer", "<init>", "(Ljava/lang/String;)V", false),
+ VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))
}
@Test
@@ -213,8 +209,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t").instructions.dropNonOp,
- List(Op(ICONST_0), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(Op(ICONST_0), Op(IRETURN)))
}
@Test
@@ -230,14 +225,12 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(
- getSingleMethod(c, "t").instructions.dropNonOp,
- List(
- IntOp(BIPUSH, 30), VarOp(ISTORE, 3), // no constant propagation, so we keep the store (and load below) of a const
- VarOp(ILOAD, 1),
- VarOp(ILOAD, 2),
- VarOp(ILOAD, 3),
- Invoke(INVOKESTATIC, "C", "C$$$anonfun$1", "(III)I", false), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t"), List(
+ IntOp(BIPUSH, 30), VarOp(ISTORE, 3), // no constant propagation, so we keep the store (and load below) of a const
+ VarOp(ILOAD, 1),
+ VarOp(ILOAD, 2),
+ VarOp(ILOAD, 3),
+ Invoke(INVOKESTATIC, "C", "C$$$anonfun$1", "(III)I", false), Op(IRETURN)))
}
@Test
@@ -342,14 +335,14 @@ class MethodLevelOptsTest extends ClearAfterClass {
assertNoInvoke(getSingleMethod(c, "t5"))
assertNoInvoke(getSingleMethod(c, "t6"))
assertNoInvoke(getSingleMethod(c, "t7"))
- assertEquals(getSingleMethod(c, "t8").instructions.summary, List(ICONST_0, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t8"), List(ICONST_0, IRETURN))
assertNoInvoke(getSingleMethod(c, "t9"))
// t10: no invocation of unbox
assertEquals(getSingleMethod(c, "t10").instructions collect { case Invoke(_, owner, name, _, _) => (owner, name) }, List(
("java/lang/Integer", "valueOf"),
("C", "escape")))
- assertEquals(getSingleMethod(c, "t11").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t11"), List(
BIPUSH, "valueOf", ASTORE /*2*/,
BIPUSH, "valueOf", ASTORE /*3*/,
ALOAD /*0*/, ALOAD /*2*/, "escape",
@@ -410,9 +403,9 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t1").instructions.summary, List(ICONST_0, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t1"), List(ICONST_0, IRETURN))
assertNoInvoke(getSingleMethod(c, "t2"))
- assertEquals(getSingleMethod(c, "t3").instructions.summary, List(LDC, LDC, LADD, LRETURN))
+ assertSameSummary(getSingleMethod(c, "t3"), List(LDC, LDC, LADD, LRETURN))
assertNoInvoke(getSingleMethod(c, "t4"))
assertEquals(getSingleMethod(c, "t5").instructions collect { case Field(_, owner, name, _) => s"$owner.$name" },
List("scala/runtime/IntRef.elem"))
@@ -475,16 +468,16 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
assertNoInvoke(getSingleMethod(c, "t1"))
- assertEquals(getSingleMethod(c, "t2").instructions.summary, List(ICONST_1, ICONST_3, IADD, IRETURN))
- assertEquals(getSingleMethod(c, "t3").instructions.summary, List(ICONST_3, ICONST_4, IADD, IRETURN))
- assertEquals(getSingleMethod(c, "t4").instructions.summary, List(ICONST_3, "boxToInteger", ARETURN))
+ assertSameSummary(getSingleMethod(c, "t2"), List(ICONST_1, ICONST_3, IADD, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t3"), List(ICONST_3, ICONST_4, IADD, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t4"), List(ICONST_3, "boxToInteger", ARETURN))
assertEquals(getSingleMethod(c, "t5").instructions collect { case Invoke(_, owner, name, _, _) => (owner, name) }, List(
("scala/runtime/BoxesRunTime", "boxToInteger"),
("scala/runtime/BoxesRunTime", "boxToInteger"),
("C", "tpl"),
("scala/Tuple2", "_1$mcI$sp")))
- assertEquals(getSingleMethod(c, "t6").instructions.summary, List(ICONST_1, ICONST_2, ISUB, IRETURN))
- assertEquals(getSingleMethod(c, "t7").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t6"), List(ICONST_1, ICONST_2, ISUB, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t7"), List(
ICONST_1, ICONST_2, ISTORE, ISTORE,
ICONST_3, ISTORE,
ILOAD, ILOAD, IADD, ILOAD, IADD, IRETURN))
@@ -539,13 +532,13 @@ class MethodLevelOptsTest extends ClearAfterClass {
|}
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t1").instructions.summary, List(NEW, DUP, "<init>", ARETURN))
- assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(Op(LCONST_0), Op(LRETURN)))
- assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(Op(ICONST_1), Op(IRETURN)))
- assertSameCode(getSingleMethod(c, "t4").instructions.dropNonOp, List(Op(ICONST_1), Op(IRETURN)))
- assertSameCode(getSingleMethod(c, "t5").instructions.dropNonOp, List(Op(DCONST_0), Op(DRETURN)))
- assertSameCode(getSingleMethod(c, "t6").instructions.dropNonOp, List(Op(ACONST_NULL), Op(ARETURN)))
- assertSameCode(getSingleMethod(c, "t7").instructions.dropNonOp, List(Op(ICONST_0), Op(IRETURN)))
+ assertSameSummary(getSingleMethod(c, "t1"), List(NEW, DUP, "<init>", ARETURN))
+ assertSameCode(getSingleMethod(c, "t2"), List(Op(LCONST_0), Op(LRETURN)))
+ assertSameCode(getSingleMethod(c, "t3"), List(Op(ICONST_1), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t4"), List(Op(ICONST_1), Op(IRETURN)))
+ assertSameCode(getSingleMethod(c, "t5"), List(Op(DCONST_0), Op(DRETURN)))
+ assertSameCode(getSingleMethod(c, "t6"), List(Op(ACONST_NULL), Op(ARETURN)))
+ assertSameCode(getSingleMethod(c, "t7"), List(Op(ICONST_0), Op(IRETURN)))
}
@Test
@@ -560,8 +553,8 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
assertSameCode(
- getSingleMethod(c, "t").instructions.dropNonOp,
- List(VarOp(ALOAD, 1), Jump(IFNULL, Label(6)), Op(ICONST_1), Op(IRETURN), Label(6), Op(ICONST_0), Op(IRETURN)))
+ getSingleMethod(c, "t"), List(
+ VarOp(ALOAD, 1), Jump(IFNULL, Label(6)), Op(ICONST_1), Op(IRETURN), Label(6), Op(ICONST_0), Op(IRETURN)))
}
@Test
@@ -703,15 +696,8 @@ class MethodLevelOptsTest extends ClearAfterClass {
assertEquals(locals(c, "t2"), List(("this", 0), ("x", 1)))
// we don't have constant propagation (yet).
// the local var can't be optimized as a store;laod sequence, there's a GETSTATIC between the two
- assertEquals(
- textify(findAsmMethod(c, "t2")),
- getSingleMethod(c, "t2").instructions.dropNonOp.map(_.opcode),
- List(
- ICONST_2, ISTORE,
- GETSTATIC, // Predef.MODULE$
- ILOAD, INVOKESTATIC, // boxToInteger
- INVOKEVIRTUAL, // println
- RETURN))
+ assertSameSummary(getSingleMethod(c, "t2"), List(
+ ICONST_2, ISTORE, GETSTATIC, ILOAD, "boxToInteger", "println", RETURN))
assertEquals(locals(c, "t3"), List(("this", 0)))
assertEquals(locals(c, "t4"), List(("this", 0), ("x", 1)))
@@ -736,10 +722,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
val t = getSingleMethod(c, "t")
assertEquals(t.handlers, Nil)
assertEquals(locals(c, "t"), List(("this", 0)))
- assertEquals(t.instructions.summary,
- List(
- GETSTATIC, LDC, "print",
- -1, GOTO))
+ assertSameSummary(t, List(GETSTATIC, LDC, "print", -1, GOTO))
}
@Test
@@ -769,7 +752,7 @@ class MethodLevelOptsTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(methodOptCompiler)(code)
- assertEquals(getSingleMethod(c, "t").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t"), List(
BIPUSH, ILOAD, IF_ICMPNE,
BIPUSH, ILOAD, IF_ICMPNE,
LDC, ASTORE, GOTO,
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala
index 902709e041..0021a1784d 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala
@@ -232,35 +232,33 @@ class UnreachableCodeTest extends ClearAfterClass {
""".stripMargin
val List(c) = compileClasses(noOptCompiler)(code)
- assertEquals(getSingleMethod(c, "nl").instructions.summary, List(ACONST_NULL, ARETURN))
+ assertSameSummary(getSingleMethod(c, "nl"), List(ACONST_NULL, ARETURN))
- assertEquals(getSingleMethod(c, "nt").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "nt"), List(
NEW, DUP, LDC, "<init>", ATHROW))
- assertEquals(getSingleMethod(c, "t1").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t1"), List(
ALOAD, ACONST_NULL, "cons", RETURN))
// GenBCode introduces POP; ACONST_NULL after loading an expression of type scala.runtime.Null$,
// see comment in BCodeBodyBuilder.adapt
- assertEquals(getSingleMethod(c, "t2").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t2"), List(
ALOAD, ALOAD, "nl", POP, ACONST_NULL, "cons", RETURN))
// the bytecode generated by GenBCode is ... ATHROW; INVOKEVIRTUAL C.cons; RETURN
// the ASM classfile writer creates a new basic block (creates a label) right after the ATHROW
// and replaces all instructions by NOP*; ATHROW, see comment in BCodeBodyBuilder.adapt
// NOTE: DCE is enabled by default and gets rid of the redundant code (tested below)
- assertEquals(getSingleMethod(c, "t3").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t3"), List(
ALOAD, NEW, DUP, LDC, "<init>", ATHROW, NOP, NOP, NOP, ATHROW))
// GenBCode introduces an ATHROW after the invocation of C.nt, see BCodeBodyBuilder.adapt
// NOTE: DCE is enabled by default and gets rid of the redundant code (tested below)
- assertEquals(getSingleMethod(c, "t4").instructions.summary, List(
+ assertSameSummary(getSingleMethod(c, "t4"), List(
ALOAD, ALOAD, "nt", ATHROW, NOP, NOP, NOP, ATHROW))
val List(cDCE) = compileClasses(dceCompiler)(code)
- assertEquals(getSingleMethod(cDCE, "t3").instructions.summary, List(
- ALOAD, NEW, DUP, LDC, "<init>", ATHROW))
- assertEquals(getSingleMethod(cDCE, "t4").instructions.summary, List(
- ALOAD, ALOAD, "nt", ATHROW))
+ assertSameSummary(getSingleMethod(cDCE, "t3"), List(ALOAD, NEW, DUP, LDC, "<init>", ATHROW))
+ assertSameSummary(getSingleMethod(cDCE, "t4"), List(ALOAD, ALOAD, "nt", ATHROW))
}
}
diff --git a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
index 3fc3144eb2..ac558e2e21 100644
--- a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
+++ b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
@@ -18,7 +18,7 @@ import scala.tools.testing.ClearAfterClass
object PatmatBytecodeTest extends ClearAfterClass.Clearable {
var compiler = newCompiler()
- var optCompiler = newCompiler(extraArgs = "-Yopt:l:method")
+ var optCompiler = newCompiler(extraArgs = "-Yopt:l:project")
def clear(): Unit = { compiler = null; optCompiler = null }
}
@@ -96,10 +96,9 @@ class PatmatBytecodeTest extends ClearAfterClass {
""".stripMargin
val c = compileClasses(optCompiler)(code).head
- assertEquals(textify(findAsmMethod(c, "a")), getSingleMethod(c, "a").instructions.summary,
- List(
- NEW, DUP, ICONST_1, LDC, "<init>",
- "y", ARETURN))
+ assertSameSummary(getSingleMethod(c, "a"), List(
+ NEW, DUP, ICONST_1, LDC, "<init>",
+ "y", ARETURN))
}
@Test
@@ -127,12 +126,12 @@ class PatmatBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
val c = compileClasses(optCompiler)(code).head
- assertEquals(textify(findAsmMethod(c, "a")), getSingleMethod(c, "a").instructions.summary,
- List(NEW, DUP, ICONST_1, "boxToInteger", LDC, "<init>", ASTORE /*1*/,
- ALOAD /*1*/, "y", ASTORE /*2*/,
- ALOAD /*1*/, "x", INSTANCEOF, IFNE /*R*/,
- NEW, DUP, ALOAD /*1*/, "<init>", ATHROW,
- /*R*/ -1, ALOAD /*2*/, ARETURN))
+ assertSameSummary(getSingleMethod(c, "a"), List(
+ NEW, DUP, ICONST_1, "boxToInteger", LDC, "<init>", ASTORE /*1*/,
+ ALOAD /*1*/, "y", ASTORE /*2*/,
+ ALOAD /*1*/, "x", INSTANCEOF, IFNE /*R*/,
+ NEW, DUP, ALOAD /*1*/, "<init>", ATHROW,
+ /*R*/ -1, ALOAD /*2*/, ARETURN))
}
@Test
@@ -156,7 +155,41 @@ class PatmatBytecodeTest extends ClearAfterClass {
-1 /*A*/ , NEW /*MatchError*/ , DUP, ALOAD /*1*/ , "<init>", ATHROW,
-1 /*B*/ , ILOAD, IRETURN)
- assertEquals(textify(findAsmMethod(c, "a")), getSingleMethod(c, "a").instructions.summary, expected)
- assertEquals(textify(findAsmMethod(c, "b")), getSingleMethod(c, "b").instructions.summary, expected)
+ assertSameSummary(getSingleMethod(c, "a"), expected)
+ assertSameSummary(getSingleMethod(c, "b"), expected)
+ }
+
+ @Test
+ def valPatterns(): Unit = {
+ val code =
+ """case class C(a: Any, b: Int) {
+ | def tplCall = ("hi", 3)
+ | @inline final def tplInline = (true, 'z')
+ |
+ | def t1 = { val (a, b) = (1, 2); a + b }
+ | def t2 = { val (a, _) = (1, 3); a }
+ | def t3 = { val (s, i) = tplCall; s.length + i }
+ | def t4 = { val (_, i) = tplCall; i }
+ | def t5 = { val (b, c) = tplInline; b || c == 'e' }
+ | def t6 = { val (_, c) = tplInline; c }
+ |
+ | def t7 = { val C(s: String, b) = this; s.length + b }
+ | def t8 = { val C(_, b) = this; b }
+ | def t9 = { val C(a, _) = C("hi", 23); a.toString }
+ |}
+ """.stripMargin
+ val List(c, cMod) = compileClasses(optCompiler)(code)
+ assertSameSummary(getSingleMethod(c, "t1"), List(ICONST_1, ICONST_2, IADD, IRETURN))
+ assertSameSummary(getSingleMethod(c, "t2"), List(ICONST_1, IRETURN))
+ assertInvokedMethods(getSingleMethod(c, "t3"), List("C.tplCall", "scala/Tuple2._1", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>", "java/lang/String.length"))
+ assertInvokedMethods(getSingleMethod(c, "t4"), List("C.tplCall", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>"))
+ assertNoInvoke(getSingleMethod(c, "t5"))
+ assertSameSummary(getSingleMethod(c, "t6"), List(BIPUSH, IRETURN))
+
+ // MatchError reachable because of the type pattern `s: String`
+ assertInvokedMethods(getSingleMethod(c, "t7"), List("C.a", "C.b", "scala/MatchError.<init>", "java/lang/String.length"))
+ assertSameSummary(getSingleMethod(c, "t8"), List(ALOAD, "b", IRETURN))
+ // C allocation not eliminated - constructor may have side-effects.
+ assertSameSummary(getSingleMethod(c, "t9"), List(NEW, DUP, LDC, BIPUSH, "<init>", "a", "toString", ARETURN))
}
}
diff --git a/test/scaladoc/run/SI-6017.scala b/test/scaladoc/run/SI-6017.scala
deleted file mode 100644
index 9951534c6d..0000000000
--- a/test/scaladoc/run/SI-6017.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-import scala.tools.nsc.doc
-import scala.tools.nsc.doc.model._
-import scala.tools.nsc.doc.html.page.{Index, ReferenceIndex}
-import scala.tools.partest.ScaladocModelTest
-
-object Test extends ScaladocModelTest {
- override def scaladocSettings = ""
- override def code = """
- class STAR
- class Star
- """
-
- def testModel(rootPackage: Package) {
- model match {
- case Some(universe) => {
- val index = IndexModelFactory.makeIndex(universe)
- // Because "STAR" and "Star" are different
- assert(index.firstLetterIndex('s').keys.toSeq.length == 2)
-
- val indexPage = new Index(universe, index)
- val letters = indexPage.letters
- assert(letters.length > 1)
- assert(letters(0).toString == "<span>#</span>")
- }
- case _ => assert(false)
- }
- }
-}
diff --git a/test/scaladoc/run/SI-9620.scala b/test/scaladoc/run/SI-9620.scala
index 96260aad9a..cac34d1c18 100644
--- a/test/scaladoc/run/SI-9620.scala
+++ b/test/scaladoc/run/SI-9620.scala
@@ -21,7 +21,6 @@ object Test extends ScaladocModelTest {
}
"""
- // no need for special settings
def scaladocSettings = "-implicits"
def testModel(rootPackage: Package) = {
diff --git a/test/scaladoc/run/SI-6017.check b/test/scaladoc/run/shortDescription-annotation.check
index 619c56180b..619c56180b 100644
--- a/test/scaladoc/run/SI-6017.check
+++ b/test/scaladoc/run/shortDescription-annotation.check
diff --git a/test/scaladoc/run/shortDescription-annotation.scala b/test/scaladoc/run/shortDescription-annotation.scala
new file mode 100644
index 0000000000..0e2950f4f9
--- /dev/null
+++ b/test/scaladoc/run/shortDescription-annotation.scala
@@ -0,0 +1,55 @@
+import scala.tools.nsc.doc.model._
+import scala.tools.partest.ScaladocModelTest
+
+object Test extends ScaladocModelTest {
+ override def code = """
+ package a
+
+ /** This comment should not appear
+ * @shortDescription This one should appear
+ */
+ class Foo {
+ /** This comment should appear */
+ def foo: Int = 1
+
+ /** This comment should not appear
+ * @shortDescription This comment should appear
+ */
+ def goo: Int = 2
+ }
+ """
+
+ // no need for special settings
+ def scaladocSettings = ""
+
+ def testModel(rootPackage: Package) = {
+ import scala.tools.nsc.doc.base.comment._
+ import access._
+
+ def inlineToStr(inl: Inline): String = inl match {
+ case Chain(items) => items flatMap (inlineToStr(_)) mkString ""
+ case Italic(in) => inlineToStr(in)
+ case Bold(in) => inlineToStr(in)
+ case Underline(in) => inlineToStr(in)
+ case Monospace(in) => inlineToStr(in)
+ case Text(text) => text
+ case Summary(in) => inlineToStr(in)
+ case EntityLink(Text(text), _) => text
+ case _ => inl.toString
+ }
+
+ val foo = rootPackage._package("a")._class("Foo")
+
+ // Assert that the class has the correct short description
+ val classDesc = inlineToStr(foo.comment.get.short)
+ assert(classDesc == "This one should appear", classDesc)
+
+ // Assert that the `foo` method has the correct short description
+ val fooDesc = inlineToStr(foo._method("foo").comment.get.short)
+ assert(fooDesc == "This comment should appear", fooDesc)
+
+ // Assert that the `goo` method has the correct short description
+ val gooDesc = inlineToStr(foo._method("goo").comment.get.short)
+ assert(gooDesc == "This comment should appear", gooDesc)
+ }
+}
diff --git a/test/scaladoc/scalacheck/DeprecatedIndexTest.scala b/test/scaladoc/scalacheck/DeprecatedIndexTest.scala
index 4a5a2001d4..2581b879da 100644
--- a/test/scaladoc/scalacheck/DeprecatedIndexTest.scala
+++ b/test/scaladoc/scalacheck/DeprecatedIndexTest.scala
@@ -1,6 +1,7 @@
import org.scalacheck._
import org.scalacheck.Prop._
+import scala.tools.nsc.ScalaDocReporter
import scala.tools.nsc.doc
import scala.tools.nsc.doc.html.page.DeprecatedIndex
import java.net.{URLClassLoader, URLDecoder}
@@ -32,7 +33,8 @@ object Test extends Properties("IndexScript") {
def createDeprecatedScript(path: String) =
docFactory.makeUniverse(Left(List(path))) match {
case Some(universe) => {
- val index = new DeprecatedIndex(universe, indexModelFactory.makeIndex(universe))
+ val reporter = new ScalaDocReporter(universe.settings)
+ val index = new DeprecatedIndex(universe, indexModelFactory.makeIndex(universe), reporter)
Some(index)
}
case _ =>
diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.scala b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
index f0f106b293..daa7de8545 100644
--- a/test/scaladoc/scalacheck/HtmlFactoryTest.scala
+++ b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
@@ -26,6 +26,8 @@ object Test extends Properties("HtmlFactory") {
final val RESOURCES = "test/scaladoc/resources/"
+
+ import scala.tools.nsc.ScalaDocReporter
import scala.tools.nsc.doc.{DocFactory, Settings}
import scala.tools.nsc.doc.model.IndexModelFactory
import scala.tools.nsc.doc.html.HtmlFactory
@@ -59,7 +61,7 @@ object Test extends Properties("HtmlFactory") {
createFactory.makeUniverse(Left(List(RESOURCES+basename))) match {
case Some(universe) => {
val index = IndexModelFactory.makeIndex(universe)
- (new HtmlFactory(universe, index)).writeTemplates((page) => {
+ (new HtmlFactory(universe, index, new ScalaDocReporter(universe.settings))).writeTemplates((page) => {
result += (page.absoluteLinkTo(page.path) -> page.body)
})
}
@@ -75,7 +77,8 @@ object Test extends Properties("HtmlFactory") {
val index = IndexModelFactory.makeIndex(universe)
val pages = index.firstLetterIndex.map({
case (key, value) => {
- val page = new ReferenceIndex(key, index, universe)
+ val reporter = new ScalaDocReporter(universe.settings)
+ val page = new ReferenceIndex(key, index, universe, reporter)
page.absoluteLinkTo(page.path) -> page.body
}
})
@@ -723,9 +726,9 @@ object Test extends Properties("HtmlFactory") {
}
case _ => false
}
- property("package") = files.get("com/example/p1/package.html") != None
+ property("package") = files.get("com/example/p1/index.html") != None
- property("package object") = files("com/example/p1/package.html") match {
+ property("package object") = files("com/example/p1/index.html") match {
case node: scala.xml.Node =>
node.toString contains "com.example.p1#packageObjectMethod"
case _ => false
@@ -743,13 +746,13 @@ object Test extends Properties("HtmlFactory") {
property("SI-8514: No inconsistencies") =
checkText("SI-8514.scala")(
- (Some("a/package"),
+ (Some("a/index"),
"""class A extends AnyRef
Some doc here
Some doc here
Annotations @DeveloperApi()
""", true),
- (Some("a/package"),
+ (Some("a/index"),
"""class B extends AnyRef
Annotations @DeveloperApi()
""", true)
@@ -794,28 +797,28 @@ object Test extends Properties("HtmlFactory") {
case _ => false
}
- property("SI-8144: Members' permalink - package") = check("some/package.html") { node =>
- ("type link" |: node.assertTypeLink("../index.html#some.package")) &&
- ("member: some.pack" |: node.assertValuesLink("some.pack", "../index.html#some.package@pack"))
+ property("SI-8144: Members' permalink - package") = check("some/index.html") { node =>
+ ("type link" |: node.assertTypeLink("../some/index.html")) &&
+ ("member: some.pack" |: node.assertValuesLink("some.pack", "../some/index.html#pack"))
}
- property("SI-8144: Members' permalink - inner package") = check("some/pack/package.html") { node =>
- ("type link" |: node.assertTypeLink("../../index.html#some.pack.package")) &&
- ("member: SomeType (object)" |: node.assertValuesLink("some.pack.SomeType", "../../index.html#some.pack.package@SomeType")) &&
- ("member: SomeType (class)" |: node.assertMemberLink("types")("some.pack.SomeType", "../../index.html#some.pack.package@SomeTypeextendsAnyRef"))
+ property("SI-8144: Members' permalink - inner package") = check("some/pack/index.html") { node =>
+ ("type link" |: node.assertTypeLink("../../some/pack/index.html")) &&
+ ("member: SomeType (object)" |: node.assertValuesLink("some.pack.SomeType", "../../some/pack/index.html#SomeType")) &&
+ ("member: SomeType (class)" |: node.assertMemberLink("types")("some.pack.SomeType", "../../some/pack/index.html#SomeTypeextendsAnyRef"))
}
property("SI-8144: Members' permalink - companion object") = check("some/pack/SomeType$.html") { node =>
- ("type link" |: node.assertTypeLink("../../index.html#some.pack.SomeType$")) &&
- ("member: someVal" |: node.assertMemberLink("allMembers")("some.pack.SomeType#someVal", "../../index.html#some.pack.SomeType$@someVal:String"))
+ ("type link" |: node.assertTypeLink("../../some/pack/SomeType$.html")) &&
+ ("member: someVal" |: node.assertMemberLink("allMembers")("some.pack.SomeType#someVal", "../../some/pack/SomeType$.html#someVal:String"))
}
property("SI-8144: Members' permalink - class") = check("some/pack/SomeType.html") { node =>
- ("type link" |: node.assertTypeLink("../../index.html#some.pack.SomeType")) &&
- ("constructor " |: node.assertMemberLink("constructors")("some.pack.SomeType#<init>", "../../index.html#some.pack.SomeType@<init>(arg:String):some.pack.SomeType")) &&
- ( "member: type TypeAlias" |: node.assertMemberLink("types")("some.pack.SomeType.TypeAlias", "../../index.html#some.pack.SomeType@TypeAlias=String")) &&
- ( "member: def >#<():Int " |: node.assertValuesLink("some.pack.SomeType#>#<", "../../index.html#some.pack.SomeType@>#<():Int")) &&
- ( "member: def >@<():TypeAlias " |: node.assertValuesLink("some.pack.SomeType#>@<", "../../index.html#some.pack.SomeType@>@<():SomeType.this.TypeAlias"))
+ ("type link" |: node.assertTypeLink("../../some/pack/SomeType.html")) &&
+ ("constructor " |: node.assertMemberLink("constructors")("some.pack.SomeType#<init>", "../../some/pack/SomeType.html#<init>(arg:String):some.pack.SomeType")) &&
+ ( "member: type TypeAlias" |: node.assertMemberLink("types")("some.pack.SomeType.TypeAlias", "../../some/pack/SomeType.html#TypeAlias=String")) &&
+ ( "member: def >#<():Int " |: node.assertValuesLink("some.pack.SomeType#>#<", "../../some/pack/SomeType.html#>#<():Int")) &&
+ ( "member: def >@<():TypeAlias " |: node.assertValuesLink("some.pack.SomeType#>@<", "../../some/pack/SomeType.html#>@<():SomeType.this.TypeAlias"))
}
}
diff --git a/test/scaladoc/scalacheck/IndexTest.scala b/test/scaladoc/scalacheck/IndexTest.scala
index 7dbd2103a6..036586c21d 100644
--- a/test/scaladoc/scalacheck/IndexTest.scala
+++ b/test/scaladoc/scalacheck/IndexTest.scala
@@ -1,6 +1,7 @@
import org.scalacheck._
import org.scalacheck.Prop._
+import scala.tools.nsc.ScalaDocReporter
import scala.tools.nsc.doc
import scala.tools.nsc.doc.html.page.Index
import java.net.{URLClassLoader, URLDecoder}
@@ -47,7 +48,8 @@ object Test extends Properties("Index") {
maybeUniverse match {
case Some(universe) => {
- val index = new Index(universe, indexModelFactory.makeIndex(universe))
+ val reporter = new ScalaDocReporter(universe.settings)
+ val index = new Index(universe, indexModelFactory.makeIndex(universe), reporter)
return Some(index)
}
case _ => return None
@@ -71,14 +73,6 @@ object Test extends Properties("Index") {
case None => false
}
}
- property("browser contains a script element") = {
- createIndex("src/scaladoc/scala/tools/nsc/doc/html/page/Index.scala") match {
- case Some(index) =>
- (index.browser \ "script").size == 1
-
- case None => false
- }
- }
property("package objects in index") = {
createIndex("test/scaladoc/resources/SI-5558.scala") match {
case Some(index) =>