diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-08-12 17:40:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-12 17:40:00 -0700 |
commit | 4b77734b28f82e2573446bd997e739b80de4af1d (patch) | |
tree | d87c4b98cc886aba8e5af7ebf44b1f42e0c42206 /test | |
parent | 3e0b2c2b14bdc26a40887af7a375077565f004b3 (diff) | |
parent | 2c2fd4f4b63e1d9a6ee1243637ad8bcb0deb11d6 (diff) | |
download | scala-4b77734b28f82e2573446bd997e739b80de4af1d.tar.gz scala-4b77734b28f82e2573446bd997e739b80de4af1d.tar.bz2 scala-4b77734b28f82e2573446bd997e739b80de4af1d.zip |
Merge pull request #5291 from lrytz/sd20
SD-20 Inlcude static methods in the InlineInfo in mixed compilation
Fixes scala/scala-dev#20
Diffstat (limited to 'test')
3 files changed, 56 insertions, 5 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala index a691d63471..6f098e1432 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala @@ -2,18 +2,20 @@ package scala.tools.nsc package backend.jvm package opt +import org.junit.Assert._ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.collection.JavaConverters._ import scala.collection.generic.Clearable +import scala.tools.nsc.backend.jvm.BTypes.MethodInlineInfo import scala.tools.nsc.backend.jvm.BackendReporting._ import scala.tools.testing.BytecodeTesting @RunWith(classOf[JUnit4]) class InlineInfoTest extends BytecodeTesting { - import compiler.global + import compiler._ import global.genBCode.bTypes override def compilerArgs = "-opt:l:classpath" @@ -59,4 +61,20 @@ class InlineInfoTest extends BytecodeTesting { assert(fromSyms == fromAttrs) } + + @Test // scala-dev#20 + def javaStaticMethodsInlineInfoInMixedCompilation(): Unit = { + val jCode = + """public class A { + | public static final int bar() { return 100; } + | public final int baz() { return 100; } + |} + """.stripMargin + compileClasses("class C { new A }", javaCode = List((jCode, "A.java"))) + val info = global.genBCode.bTypes.classBTypeFromInternalName("A").info.get.inlineInfo + assertEquals(info.methodInfos, Map( + "bar()I" -> MethodInlineInfo(true,false,false), + "<init>()V" -> MethodInlineInfo(false,false,false), + "baz()I" -> MethodInlineInfo(true,false,false))) + } } 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 5254d7e1f2..5bd2ce68f1 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala @@ -75,12 +75,12 @@ class InlineWarningTest extends BytecodeTesting { val warns = List( """failed to determine if bar should be inlined: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin) + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin) var c = 0 val List(b) = compileToBytes(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; warns.tail.exists(i.msg contains _)}) @@ -168,4 +168,37 @@ class InlineWarningTest extends BytecodeTesting { compileToBytes(code, allowMessage = i => { c += 1; i.msg contains warn }) assert(c == 1, c) } + + @Test // scala-dev#20 + def mixedCompilationSpuriousWarning(): Unit = { + val jCode = + """public class A { + | public static final int bar() { return 100; } + | public final int baz() { return 100; } + |} + """.stripMargin + + val sCode = + """class C { + | @inline final def foo = A.bar() + | @inline final def fii(a: A) = a.baz() + | def t = foo + fii(new A) + |} + """.stripMargin + + val warns = List( + """C::foo()I is annotated @inline but could not be inlined: + |Failed to check if C::foo()I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: + |The method bar()I could not be found in the class A or any of its parents. + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, + + """C::fii(LA;)I is annotated @inline but could not be inlined: + |Failed to check if C::fii(LA;)I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKEVIRTUAL A.baz ()I failed: + |The method baz()I could not be found in the class A or any of its parents. + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin + ) + var c = 0 + compileClasses(sCode, javaCode = List((jCode, "A.java")), allowMessage = i => { c += 1; warns.exists(i.msg.contains)}) + assert(c == 2) + } } 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 f88b95eae4..539c66a0d5 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -416,7 +416,7 @@ class InlinerTest extends BytecodeTesting { """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin var c = 0 val List(b) = compile(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; i.msg contains warn}) @@ -819,7 +819,7 @@ class InlinerTest extends BytecodeTesting { val warn = """failed to determine if <init> should be inlined: |The method <init>()V could not be found in the class A$Inner or any of its parents. - |Note that the parent class A$Inner could not be found on the classpath.""".stripMargin + |Note that class A$Inner could not be found on the classpath.""".stripMargin var c = 0 |