summaryrefslogtreecommitdiff
path: root/test/files/run/private-inline.scala
blob: 60fef9efca30da1cf73714edb19dee1950262c0a (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
final class A {
  private var x1 = false
  var x2 = false

  // manipulates private var
  @inline private def wrapper1[T](body: => T): T = {
    val saved = x1
    x1 = true
    try body
    finally x1 = saved
  }
  // manipulates public var
  @inline private def wrapper2[T](body: => T): T = {
    val saved = x2
    x2 = true
    try body
    finally x2 = saved
  }

  // not inlined
  def f1a() = wrapper1(5)
  // inlined!
  def f1b() = identity(wrapper1(5))

  // not inlined
  def f2a() = wrapper2(5)
  // inlined!
  def f2b() = identity(wrapper2(5))
}

object Test {
  def methodClasses = List("f1a", "f2a") map ("A$$anonfun$" + _ + "$1")

  def main(args: Array[String]): Unit = {
    val a = new A
    import a._
    println(f1a() + f1b() + f2a() + f2b())

    // Don't know how else to test this: all these should have been
    // inlined, so all should fail.
    methodClasses foreach { clazz =>

      val foundClass = (
        try   Class.forName(clazz)
        catch { case _: Throwable => null }
      )

      assert(foundClass == null, foundClass)
    }
  }
}