Skip to content

Commit 0a6bc93

Browse files
committed
Add a tricky example for #1856
1 parent 8b8fc17 commit 0a6bc93

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

tests/run/i1856.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ Iteration 7
99
Iteration 8
1010
Iteration 9
1111
42
12-

tests/run/i1856b.check

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Iteration 0
2+
Iteration 1
3+
Iteration 2
4+
Iteration 3
5+
Iteration 4
6+
Iteration 5
7+
Iteration 6
8+
Iteration 7
9+
Iteration 8
10+
Iteration 9
11+
Lzy has been read as: 42
12+
Lzy has been read as: 43
13+
Lzy has been read as: 44
14+
Lzy has been read as: 45
15+
Lzy has been read as: 46
16+
Lzy has been read as: 47
17+
Lzy has been read as: 48
18+
Lzy has been read as: 49
19+
Lzy has been read as: 50
20+
Lzy has been read as: 51
21+
52
22+
Lzy has been read as: 52

tests/run/i1856b.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object Test {
2+
var count: Int = 0
3+
def getLzy = {
4+
val read = lzy
5+
println("Lzy has been read as: " +read)
6+
read
7+
}
8+
9+
lazy val lzy: Int = {
10+
if (count < 10) {
11+
println(s"Iteration $count")
12+
count += 1
13+
getLzy + 1
14+
} else 42
15+
}
16+
17+
def main(args: Array[String]): Unit = {
18+
println(lzy)
19+
getLzy
20+
}
21+
}

0 commit comments

Comments
 (0)