File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,25 @@ enum Color:
44enum Player :
55 case Black , White
66
7+ // Explanation: See the desugaring below
78 val color : Color =
89 if this == Player .Black // warn
910 then Color .Black
1011 else Color .White
12+
13+ // From the desugaring of Player, we can see the field `Player.Black` is not yet
14+ // initialized during evaluation of the first `new Player`:
15+ //
16+ // class Player:
17+ // val color: Color =
18+ // if this == Player.Black ...
19+ //
20+ // object Player:
21+ // val Black: Player = new Player // <--- problem
22+ // val White: Player = new Player
23+ //
24+ //
25+ // The complex desugaring makes it difficult to see the initialization
26+ // semantics and it is prone to make such hard-to-spot mistakes.
27+ //
28+ // Note: The desugaring above is simplified for presentation.
You can’t perform that action at this time.
0 commit comments