Unsound reduction of match types with refined trait member as scrutinee
Opened this issue · 1 comments
EugeneFlesselle commented
Compiler version
3.5.0-RC1
Minimized code
This is another instance of #19746 except the prefix is a trait value instead of a function parameter.
trait V:
type X = this.type match
case W[x] => x
trait W[+Y] extends V
trait T:
val w: W[Any]
val x: w.X = 0
object U extends T:
val w: W[Boolean] = new W[Boolean] {}
@main def Test =
val b: Boolean = U.x : U.w.X // ClassCastException
smarter commented
Another variation I came up with before I realized this issue already existed:
class W[+Y]
object W:
type Extract[A] = A match
case W[x] => x
trait Base[+T]:
val w: T
def take(x: W.Extract[w.type]): Int
class SubInt extends Base[W[Int]]:
val w: W[Int] = W[Int]()
def take(x: W.Extract[w.type]): Int = x
@main def run =
val b: Base[W[Any]] = SubInt()
val i: Int = b.take("") // ClassCastException