summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-08-15 09:52:59 +1000
committerGitHub <noreply@github.com>2016-08-15 09:52:59 +1000
commit391d954fc112f8aea55b471f82e40b888983ca95 (patch)
tree61745d544c6aace6741cadefaa1b638f87e1914e /test
parent804133f60dd3c78909dc9e557e91b5c9923240ff (diff)
parenta0590aa9ba45e83c8c8d496b8ab132966b1a7a95 (diff)
downloadscala-391d954fc112f8aea55b471f82e40b888983ca95.tar.gz
scala-391d954fc112f8aea55b471f82e40b888983ca95.tar.bz2
scala-391d954fc112f8aea55b471f82e40b888983ca95.zip
Merge pull request #5283 from lrytz/sd182
SD-182 compiler option -Xgen-mixin-forwarders
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/lang/traits/BytecodeTest.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/junit/scala/lang/traits/BytecodeTest.scala b/test/junit/scala/lang/traits/BytecodeTest.scala
index ec8508df99..e6c74b86ab 100644
--- a/test/junit/scala/lang/traits/BytecodeTest.scala
+++ b/test/junit/scala/lang/traits/BytecodeTest.scala
@@ -230,6 +230,35 @@ class BytecodeTest extends BytecodeTesting {
List(ALOAD, ILOAD, PUTFIELD, ALOAD, ACONST_NULL, "<init>", RETURN))
}
+ @Test
+ def mixinForwarders(): Unit = {
+ val code =
+ """trait T { def f = 1 }
+ |class C extends T
+ """.stripMargin
+ val List(c1, _) = compileClasses(code)
+ val List(c2, _) = newCompiler(extraArgs = "-Xgen-mixin-forwarders").compileClasses(code)
+ assert(getMethods(c1, "f").isEmpty)
+ assertSameCode(getMethod(c2, "f"),
+ List(VarOp(ALOAD, 0), Invoke(INVOKESTATIC, "T", "f$", "(LT;)I", true), Op(IRETURN)))
+ }
+
+ @Test
+ def sd143(): Unit = {
+ // this tests the status quo, which is wrong.
+ val code =
+ """class A { def m = 1 }
+ |class B extends A { override def m = 2 }
+ |trait T extends A
+ |class C extends B with T {
+ | override def m = super[T].m // should invoke A.m
+ |}
+ """.stripMargin
+ val List(_, _, c, _) = compileClasses(code)
+ // even though the bytecode refers to A.m, invokespecial will resolve to B.m
+ assertSameCode(getMethod(c, "m"),
+ List(VarOp(ALOAD, 0), Invoke(INVOKESPECIAL, "A", "m", "()I", false), Op(IRETURN)))
+ }
}
object invocationReceiversTestCode {