You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sealedabstractclassRPS(valscore:Int, valbeats:RPS)
caseobjectRockextendsRPS(1, Scissors)
caseobjectPaperextendsRPS(2, Rock)
caseobjectScissorsextendsRPS(3, Paper)
println(Rock.beats) // prints Scissors
println(Paper.beats) // prints null
println(Scissors.beats) // prints Paper
Problem
Paper.beats should be evaluated to Rock and not null.
When you evaluate only Paper.beats it works just fine, but if all three are printed then it produces null.
The text was updated successfully, but these errors were encountered:
Someone just posted an issue about initialization of circular dependencies. I don't know if this is a "normal" modelling concern or exacerbated by the season of puzzling.
Consider the local case:
object X {
sealed abstract class RPS(val score: Int, val beats: RPS)
case object Rock extends RPS(1, Scissors)
case object Paper extends RPS(2, Rock)
case object Scissors extends RPS(3, Paper)
}
object Test extends App {
import X._
println(Rock.beats) // prints Scissors
println(Paper.beats) // prints null
println(Scissors.beats) // prints Paper
def f: Unit = {
sealed abstract class RPS(val score: Int, val beats: RPS)
case object Rock extends RPS(1, Scissors)
case object Paper extends RPS(2, Rock)
case object Scissors extends RPS(3, Paper)
println(Rock.beats) // prints Scissors
println(Paper.beats) // prints null
println(Scissors.beats) // prints Paper
}
f
}
Reproduction steps
Scala version: 2.3.8
Problem
Paper.beats should be evaluated to Rock and not null.
When you evaluate only
Paper.beats
it works just fine, but if all three are printed then it produces null.The text was updated successfully, but these errors were encountered: