Skip to content

Misleading warning "Unreachable case except for null" (and one more issue) #15661

Closed
@strelec

Description

@strelec

Compiler version

Tested both 3.1.3 and 3.2.0-RC1

Minimized code

case class Composite[T](l: List[T], v: T)

def m(composite: Composite[_]): Unit =
  composite match {
    case Composite(l: List[Int], v: Int) => println(v)
    case _ => println("This is not Int")
  }

Output

Two bad warnings. First one is major, second one minor. Reporting both together, because I think they have the same root cause.

  1. Unreachable case except for null (if this is intentional, consider writing case null => instead).

Strangely, If I follow the advice and specify case null => I get a proper match may not be exhaustive. warning.

  1. the type test for List[Int] cannot be checked at runtime

Explanation: List[Int] does not need to be checked at runtime, because matching second parameter as Int fixes the possible type of the list.

Expectation

No warnings at all.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions