scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Spurious "unreachable code" warning with confused prefixes #9220

Closed scabug closed 6 years ago

scabug commented 9 years ago

The following,

trait Command
object Command {
  sealed trait Execution extends Command
}

case class Buzz() extends Command.Execution
case class Door() extends Command.Execution

def foo(cmd: Command.Execution) = cmd match {
  case x @ (_: Buzz) => ???
  case x @ (_: Door) => ???
}

results in the following spurious unreachable code warning,

[error]  bug.scala:11: unreachable code
[error]       case x @ (_: Door) => ???
[error]                             ^

Unnesting the Execution trait from the Command companion object results in compilation without the complaint.

scabug commented 9 years ago

Imported From: https://issues.scala-lang.org/browse/SI-9220?orig=1 Reporter: @milessabin Affected Versions: 2.11.6

scabug commented 9 years ago

@retronym said:

object Test {
  trait Command
  object Command {
    sealed trait Execution extends Command
  }

  case class Buzz() extends Command.Execution
  case class Door() extends Command.Execution

  def foo(cmd: Command.Execution) = cmd match {
    case x @ (_: Buzz) => ???
    case x @ (_: Door) => ???
  }
}
scabug commented 9 years ago

@retronym said: WIP: https://github.com/retronym/scala/tree/ticket/9220

OlivierBlanvillain commented 6 years ago

This issue seams to be fixed in 2.12.

SethTisue commented 6 years ago

I'm unable to reproduce it in 2.10 or 2.11 either, though. That has me wondering if some special compiler flag is required, or what. (I do have -Xlint enabled.)

Jasper-M commented 6 years ago

@SethTisue Strange, I can reproduce it without any special flags in every version I tried except for 2.12.x

SethTisue commented 6 years ago

oh, never mind, I can reproduce it with Jason's version of the code.

SethTisue commented 6 years ago

and yup, fixed in 2.12