File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
docs/docs/reference/changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,12 @@ initialized by some thread. The state 2 denotes that there are concurrent reader
6969The state 3 represents a lazy val that has been initialized. ` <field-id> ` is the id of the lazy
7070val. This id grows with the number of volatile lazy vals defined in the class.
7171
72+ ## Note on recursive lazy vals
73+
74+ Ideally recursive lazy vals should be flagged as an error. The current behavior for ` @volatile `
75+ recursive lazy vals is undefined (initialization may result in a deadlock). Non ` @volatile ` lazy
76+ vals behave as in Scala 2.
77+
7278## Reference
7379
7480* [ SIP-20]
Original file line number Diff line number Diff line change 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+ 42
12+ Iteration 0
13+ Iteration 1
14+ Iteration 2
15+ Iteration 3
16+ Iteration 4
17+ Iteration 5
18+ Iteration 6
19+ Iteration 7
20+ Iteration 8
21+ Iteration 9
22+ 42
Original file line number Diff line number Diff line change 1+ object Test {
2+ var count = 0
3+ lazy val lzy : Int = {
4+ if (count < 10 ) {
5+ println(s " Iteration $count" )
6+ count += 1
7+ lzy
8+ } else 42
9+ }
10+
11+ def lzy2 = {
12+ var countLocal = 0
13+ lazy val lzyLocal : Int = {
14+ if (countLocal < 10 ) {
15+ println(s " Iteration $countLocal" )
16+ countLocal += 1
17+ lzyLocal
18+ } else 42
19+ }
20+ lzyLocal
21+ }
22+
23+ def main (args : Array [String ]): Unit = {
24+ println(lzy)
25+ println(lzy2)
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments