Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious "unreachable code" warning with confused prefixes #9220

Closed
scabug opened this issue Mar 12, 2015 · 8 comments
Closed

Spurious "unreachable code" warning with confused prefixes #9220

scabug opened this issue Mar 12, 2015 · 8 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Mar 12, 2015

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
Copy link
Author

scabug commented Mar 12, 2015

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

@scabug
Copy link
Author

scabug commented Mar 13, 2015

@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
Copy link
Author

scabug commented Mar 13, 2015

@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@OlivierBlanvillain
Copy link

This issue seams to be fixed in 2.12.

@SethTisue
Copy link
Member

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
Copy link
Member

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

@SethTisue
Copy link
Member

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

@SethTisue
Copy link
Member

and yup, fixed in 2.12

@SethTisue SethTisue modified the milestones: Backlog, 2.12.0 Nov 23, 2017
Jasper-M added a commit to Jasper-M/scala that referenced this issue Nov 23, 2017
Jasper-M added a commit to Jasper-M/scala that referenced this issue Nov 23, 2017
lrytz added a commit to scala/scala that referenced this issue Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants