Skip to content

failed to produce a warning about inexhaustive pattern #22590

Closed
@theosotr

Description

@theosotr

Compiler version

3.6.3

Minimized code

sealed trait T_A
case class CC_B[T](a: T) extends T_A

@main def test() = {
  val v_a: CC_B[Int] = CC_B(10)
  val v_b: Int = v_a match{
    case CC_B(12) => 0 
  }
}

Output

The compiler does not produce any warning during compilation. However, there's a MatchError at runtime

Exception in thread "main" scala.MatchError: CC_B(10) (of class CC_B)
        at test$package$.test(test.scala:7)
        at test.main(test.scala:4)

Expectation

A compile-time warning that the pattern is not exhaustive.

Notably, in the following scenario (where there are two parameters in CC_B), the compiler warns about the inexhaustive pattern as expected:

sealed trait T_B
case class CC_A() extends T_B
case class CC_C() extends T_B

sealed trait T_A
case class CC_B[B](a: B,b:T_B) extends T_A


@main def test() = {
  val v_a: CC_B[Int] = null
  val v_b: Int = v_a match {
    case CC_B(12, CC_A()) => 0 
    case CC_B(_, CC_C()) => 0 
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions