diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-08-20 12:28:30 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-08-27 09:23:46 +0200 |
commit | 617c0923bd6b5d1642d04a03508f063d503776b6 (patch) | |
tree | 3fe04388dbbf0d2fd0d3ca5dad482099134f4882 /test/junit | |
parent | 3deb2242cba85a618da88dd98846290f359ab3a6 (diff) | |
download | scala-617c0923bd6b5d1642d04a03508f063d503776b6.tar.gz scala-617c0923bd6b5d1642d04a03508f063d503776b6.tar.bz2 scala-617c0923bd6b5d1642d04a03508f063d503776b6.zip |
Store SAM information in ClassBTypes
If a class (trait) is a SAM type, store the name and descriptor of the
SAM in the ClassBType's InlineInfo.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala index f8e887426b..c07d1fe3c4 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala @@ -9,20 +9,26 @@ import scala.tools.asm.Opcodes._ import org.junit.Assert._ import CodeGenTools._ +import scala.tools.asm.tree.ClassNode import scala.tools.nsc.backend.jvm.BTypes.{MethodInlineInfo, InlineInfo} import scala.tools.partest.ASMConverters import ASMConverters._ import scala.collection.convert.decorateAsScala._ +import scala.tools.testing.ClearAfterClass -object ScalaInlineInfoTest { +object ScalaInlineInfoTest extends ClearAfterClass.Clearable { var compiler = newCompiler(extraArgs = "-Ybackend:GenBCode -Yopt:l:none") def clear(): Unit = { compiler = null } } @RunWith(classOf[JUnit4]) -class ScalaInlineInfoTest { +class ScalaInlineInfoTest extends ClearAfterClass { + ClearAfterClass.stateToClear = ScalaInlineInfoTest + val compiler = newCompiler() + def inlineInfo(c: ClassNode): InlineInfo = c.attrs.asScala.collect({ case a: InlineInfoAttribute => a.inlineInfo }).head + @Test def traitMembersInlineInfo(): Unit = { val code = @@ -58,10 +64,11 @@ class ScalaInlineInfoTest { """.stripMargin val cs @ List(t, tl, to, tCls) = compileClasses(compiler)(code) - val List(info) = t.attrs.asScala.collect({ case a: InlineInfoAttribute => a.inlineInfo }).toList - val expect = InlineInfo( + val info = inlineInfo(t) + val expect = InlineInfo ( None, // self type false, // final class + None, // not a sam Map( ("O()LT$O$;", MethodInlineInfo(true, false,false,false)), ("T$$super$toString()Ljava/lang/String;",MethodInlineInfo(false,false,false,false)), @@ -82,4 +89,43 @@ class ScalaInlineInfoTest { ) assert(info == expect, info) } + + @Test + def inlineInfoSam(): Unit = { + val code = + """abstract class C { + | def f = 0 + | def g(x: Int): Int + | val foo = "hi" + |} + |abstract class D { + | val biz: Int + |} + |trait T { + | def h(a: String): Int + |} + |abstract class E extends T { + | def hihi(x: Int) = x + |} + |class F extends T { + | def h(a: String) = 0 + |} + |trait U { + | def conc() = 10 + | def nullary: Int + |} + """.stripMargin + val cs = compileClasses(compiler)(code) + val sams = cs.map(c => (c.name, inlineInfo(c).sam)) + assertEquals(sams, + List( + ("C",Some("g(I)I")), + ("D",None), + ("E",Some("h(Ljava/lang/String;)I")), + ("F",None), + ("T",Some("h(Ljava/lang/String;)I")), + ("U",None), + ("U$class",None))) + + } } |