summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-08-28 14:05:02 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-09-18 10:32:34 +0200
commit91cd6d1a3db422c576f15eceb0715c572ec44081 (patch)
treed4a6560b196253375b8ba70db6dc87f4603318ed
parent41e5ef4396a1526cd8c58157912ffed830a96f1e (diff)
downloadscala-91cd6d1a3db422c576f15eceb0715c572ec44081.tar.gz
scala-91cd6d1a3db422c576f15eceb0715c572ec44081.tar.bz2
scala-91cd6d1a3db422c576f15eceb0715c572ec44081.zip
Test inliner warnings for callsites not annotated @inline
Test that no warning is issued with the default flags when an inlining fails and the callee is not annotated @inline.
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala
index e78b5071e0..5f7a6d0633 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala
@@ -31,7 +31,8 @@ object InlineWarningTest extends ClearAfterClass.Clearable {
val argsNoWarn = "-Ybackend:GenBCode -Yopt:l:classpath"
val args = argsNoWarn + " -Yopt-warnings"
var compiler = newCompiler(extraArgs = args)
- def clear(): Unit = { compiler = null }
+ var compilerWarnAll = newCompiler(extraArgs = argsNoWarn + " -Yopt-warnings:_")
+ def clear(): Unit = { compiler = null; compilerWarnAll = null }
}
@RunWith(classOf[JUnit4])
@@ -39,8 +40,9 @@ class InlineWarningTest extends ClearAfterClass {
ClearAfterClass.stateToClear = InlineWarningTest
val compiler = InlineWarningTest.compiler
+ val compilerWarnAll = InlineWarningTest.compilerWarnAll
- def compile(scalaCode: String, javaCode: List[(String, String)] = Nil, allowMessage: StoreReporter#Info => Boolean = _ => false): List[ClassNode] = {
+ def compile(scalaCode: String, javaCode: List[(String, String)] = Nil, allowMessage: StoreReporter#Info => Boolean = _ => false, compiler: Global = compiler): List[ClassNode] = {
compileClasses(compiler)(scalaCode, javaCode, allowMessage)
}
@@ -171,6 +173,33 @@ class InlineWarningTest extends ClearAfterClass {
}
@Test
+ def dontWarnWhenNotIlnineAnnotated(): Unit = {
+ val code =
+ """class M {
+ | final def f(t: Int => Int) = {
+ | @noinline def nested = 0
+ | nested + t(1)
+ | }
+ | def t = f(x => x + 1)
+ |}
+ |
+ |class N {
+ | def t(a: M) = a.f(x => x + 1)
+ |}
+ """.stripMargin
+ compile(code, allowMessage = _ => false) // no warnings allowed
+
+ val warn =
+ """M::f(Lscala/Function1;)I could not be inlined:
+ |The callee M::f(Lscala/Function1;)I contains the instruction INVOKESPECIAL M.nested$1 ()I
+ |that would cause an IllegalAccessError when inlined into class N""".stripMargin
+
+ var c = 0
+ compile(code, compiler = compilerWarnAll, allowMessage = i => { c += 1; i.msg contains warn })
+ assert(c == 1, c)
+ }
+
+ @Test
def cannotMixStrictfp(): Unit = {
val code =
"""import annotation.strictfp