Skip to content

ClassCastException from simple use of pattern matching #14587

Closed
@oscar-broman

Description

@oscar-broman

Compiler version

3.1.3-RC1-bin-20220226-8922c88-NIGHTLY

Works in 3.1.2-RC1 and 3.1.0

Minimized code

def test(foo: String): Unit = {
  // Does not crash if the type is written explicitly as: Option[(Option[Int], String)]
  val bar = {
    if (foo.isEmpty) Some((Some(1), ""))
    else Some((None, ""))
  }

  bar.foreach {
    case (Some(_), "") =>
    case _ =>
  }
}

test("") // works
test("a")

Output

Exception in thread "main" java.lang.ClassCastException: class scala.None$ cannot be cast to class scala.Some (scala.None$ and scala.Some are in unnamed module of loader 'app')

Expectation


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions