In both 2.12.17 and 2.13.10
object Test {
trait MFSS[Self <: MFSS[Self]]
trait CS extends MFSS[CS]
trait MFI {
type ST
}
case class MFSD[S <: MFSS[S]](mFI: MFI { type ST = S })
case object IOS extends MFI {
type ST = CS
}
type SD = MFSD[S] forSome {
type S <: MFSS[S]
}
def bad(sd: SD) = sd.mFI match {
case ios : IOS.type => println(ios)
}
def good1(sd: SD) = (sd.mFI: MFI) match {
case ios : IOS.type => println(ios)
}
def good2(sd: SD) = sd.mFI match {
case ios @ IOS => println(ios)
}
def main(args: Array[String]): Unit = {
val x = MFSD(IOS)
good1(x)
good2(x)
bad(x)
}
}
➜ sandbox sc Test.scala && s Test
warning: 1 feature warning; re-run with -feature for details
1 warning
IOS
IOS
java.lang.ClassCastException: class Test$IOS$ cannot be cast to class scala.runtime.Null$ (Test$IOS$ and scala.runtime.Null$ are in unnamed module of loader java.net.URLClassLoader @437da279)
at Test$.bad(Test.scala:20)
at Test$.main(Test.scala:36)
In both 2.12.17 and 2.13.10