summaryrefslogtreecommitdiff
path: root/test/files/run/lazy_local_labels.scala
blob: f4a1cdf68988a850f50dd37a24dfffd3fa51bec8 (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
// should print HI nine times to indicate the lazy val has been re-initialized on every iteration
object Test extends App {
  def fooDo: Unit = {
    var i = 3
    do {
      lazy val x = { println("HI"); 1 }
      i -= x
    } while(i > 0)
  }

  def fooWhile: Unit = {
    var i = 3
    while(i > 0) {
      lazy val x = { println("HI"); 1 }
      i -= x
    }
  }

  @annotation.tailrec def fooTail(i: Int): Unit = {
    lazy val x = { println("HI"); 1 }
    if (i > 0) fooTail(i - x)
  }


  fooWhile
  fooDo
  fooTail(3)
}