Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound reduction of match types with refined trait member as scrutinee #20515

Open
EugeneFlesselle opened this issue Jun 3, 2024 · 1 comment
Assignees
Labels
area:match-types itype:bug itype:soundness Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)

Comments

@EugeneFlesselle
Copy link
Contributor

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
Copy link
Member

smarter commented Jun 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:match-types itype:bug itype:soundness Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)
Projects
None yet
Development

No branches or pull requests

3 participants