aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala
blob: 033783303df078042d6645759017c931c0cdd75d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package dotty.tools.backend.jvm

import org.junit.Assert._
import org.junit.Test

class InlineBytecodeTests extends DottyBytecodeTest {
  import ASMConverters._
  @Test def inlineUnit = {
    val source = """
                 |class Foo {
                 |  inline def foo: Int = 1
                 |
                 |  def meth1: Unit = foo
                 |  def meth2: Unit = 1
                 |}
                 """.stripMargin

    checkBCode(source) { dir =>
      val clsIn      = dir.lookupName("Foo.class", directory = false).input
      val clsNode    = loadClassNode(clsIn)
      val meth1       = getMethod(clsNode, "meth1")
      val meth2       = getMethod(clsNode, "meth2")

      val instructions1 = instructionsFromMethod(meth1)
      val instructions2 = instructionsFromMethod(meth2)

      assert(instructions1 == instructions2,
        "`foo` was not properly inlined in `meth1`\n" +
        diffInstructions(instructions1, instructions2))
    }
  }
}