-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for global init checker (#21694)
Add a test for global init checker
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
enum Color: | ||
case None, White, Black | ||
|
||
enum Player: | ||
case Black, White | ||
|
||
// Explanation: See the desugaring below | ||
val color: Color = | ||
if this == Player.Black // warn | ||
then Color.Black | ||
else Color.White | ||
|
||
// From the desugaring of Player, we can see the field `Player.Black` is not yet | ||
// initialized during evaluation of the first `new Player`: | ||
// | ||
// class Player: | ||
// val color: Color = | ||
// if this == Player.Black ... | ||
// | ||
// object Player: | ||
// val Black: Player = new Player // <--- problem | ||
// val White: Player = new Player | ||
// | ||
// | ||
// The complex desugaring makes it difficult to see the initialization | ||
// semantics and it is prone to make such hard-to-spot mistakes. | ||
// | ||
// Note: The desugaring above is simplified for presentation. |