Skip to content

Type matches are unsound. #6314

Closed
Closed
@sir-wabbit

Description

@sir-wabbit
object G {
    final class X
    final class Y

    opaque type Foo = X & Y
    object Foo {
        def apply[F[_]](fa: F[X & Y]): F[Y & Foo] = fa
    }

    type Bar[A] = A match {
        case X & Y => String
        case Y => Int
    }

    def main(args: Array[String]): Unit = {
        val a: Bar[X & Y] = "hello"
        val i: Bar[Y & Foo] = Foo.apply[Bar](a)
        val b: Int = i
        println(b + 1)
    }
}
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:103)
    at G$.main(test.scala:30)
    at G.main(test.scala)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions