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

false positive unreachable code warning #10251

Closed
Atry opened this issue Apr 9, 2017 · 2 comments
Closed

false positive unreachable code warning #10251

Atry opened this issue Apr 9, 2017 · 2 comments
Labels

Comments

@Atry
Copy link

Atry commented Apr 9, 2017

Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

sealed trait Base {
  type A
  type B
}
object Base {
  type Aux[A0, B0] = Base {
    type A = A0
    type B = B0
  }
}

trait Child0 extends Base
trait Child1 extends Base

val base: Base.Aux[Float, Float] = new Child1 {
  override type A = Float
  override type B = Float
}
base match {
  case child0: Child0 =>
    throw new AssertionError()
  case child1: Child1 =>
    child1.ensuring(_ == base)
}

// Exiting paste mode, now interpreting.

<console>:35: warning: unreachable code
           child1.ensuring(_ == base)
                          ^
defined trait Base
defined object Base
defined trait Child0
defined trait Child1
base: Base.Aux[Float,Float] = $anon$1@71ad3d8a
res0: Base{type A = Float; type B = Float} with Child1 = $anon$1@71ad3d8a

The unreachable code mentioned by the warning message is actually reachable.

@Atry Atry changed the title @unchecked causes false positive warning false positive unreachable code warning Apr 9, 2017
@Atry
Copy link
Author

Atry commented Apr 9, 2017

A workaround:

(base: { type A = Float; type B = Float}) match {
  case child0: Child0 =>
    throw new AssertionError()
  case child1: Child1 =>
    child1.ensuring(_ == base)
}

@SethTisue
Copy link
Member

consolidating at #11457

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
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

3 participants