diff --git a/tests/init-global/warn/Color.scala b/tests/init-global/warn/Color.scala index ee1c00701940..59554c905cd0 100644 --- a/tests/init-global/warn/Color.scala +++ b/tests/init-global/warn/Color.scala @@ -4,7 +4,25 @@ enum Color: 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.