Skip to content

Missing type test cannot be checked at runtime warning for match inside extractor #24282

@eejbyfeldt

Description

@eejbyfeldt

Compiler version

3.7.3, 3.8.0-RC1-bin-20251028-11ecbfb-NIGHTLY

Minimized code

object test {
  enum Expr[T] {
    case IsOpt[T](left: Expr[T]) extends Expr[Boolean]
    case Lit[T](value: T) extends Expr[T]
  }

  def main(args: Array[String]): Unit =
    val _ = Expr.IsOpt(Expr.Lit(1)) match {
      case Expr.IsOpt(opt: Expr.Lit[Option[?]]) => opt.value.isEmpty
      case _ => None
    }
}

Output

Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class scala.Option (java.lang.Integer is in module java.base of loader 'bootstrap'; scala.Option is in unnamed module of loader 'app')
	at test$.main(expr_unsafe.scala:9)
	at test.main(expr_unsafe.scala)

Expectation

There should be a warning that the type test for test.Expr.Lit[Option[_]] @_ cannot be checked at runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions