Skip to content

Commit 5d135dc

Browse files
committed
check local lazy vals in labeldefs
1 parent 68f62fe commit 5d135dc

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
HI
2+
HI
3+
HI
4+
HI
5+
HI
6+
HI
7+
HI
8+
HI
9+
HI
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// should print HI nine times to indicate the lazy val has been re-initialized on every iteration
2+
object Test extends App {
3+
def fooDo: Unit = {
4+
var i = 3
5+
do {
6+
lazy val x = { println("HI"); 1 }
7+
i -= x
8+
} while(i > 0)
9+
}
10+
11+
def fooWhile: Unit = {
12+
var i = 3
13+
while(i > 0) {
14+
lazy val x = { println("HI"); 1 }
15+
i -= x
16+
}
17+
}
18+
19+
@annotation.tailrec def fooTail(i: Int): Unit = {
20+
lazy val x = { println("HI"); 1 }
21+
if (i > 0) fooTail(i - x)
22+
}
23+
24+
25+
fooWhile
26+
fooDo
27+
fooTail(3)
28+
}

0 commit comments

Comments
 (0)