Skip to content

Invalid unreachable case warning on Java-defined class with unbounded type parameter #15717

Closed
@Arthurm1

Description

@Arthurm1

Compiler version

3.1.3

Minimized code

object TestMatch extends App {
  def getValues: Object = {
    val x = new java.util.Vector[Double]()
    x.add(1.0)
    x
  }
  val x = getValues
  x match {
    case l: java.util.Vector[_] =>
      l.get(0) match {
        case d: Double => println(s"got first $d") // unreachable case warning
        case _ => println("shrug")
      }
  }
  x match {
    case l: java.util.Vector[_] =>
      l.get(0) match {
        case d: Double => println(s"got second $d") // no warning
      }
  }
}

Output

unreachable case warning on line indicated with comment

Expectation

Running the app shows that the case is used so I'd expect no warning.

The second match statement doesn't have a warning for case d: Double so why does the first?

I get the correct warnings if getValues is not returned as Object.

I don't think this is the same as other open unreachable case issues. It doesn't involve unions or nulls

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions