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
Wrong pattern matching warning message 'unreachable code' #6146
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6146?orig=1 |
@paulp said: trait Foo extends scala.reflect.internal.SymbolTable {
def g(x: Any) = x match {
case NoType =>
case NoPrefix =>
case tpe: Type =>
case product: Product =>
}
}
/*
% m3scalac ./a.scala
% m4scalac ./a.scala
./a.scala:7: warning: unreachable code
case NoPrefix =>
^
one warning found
*/ |
@paulp said: |
@Sciss said: |
@adriaanm said: |
@adriaanm said: |
@adriaanm said (edited on Jul 27, 2012 2:24:29 PM UTC): |
@paulp said: |
@adriaanm said: |
@adriaanm said (edited on Aug 10, 2012 9:04:07 AM UTC): the problem is it requires dealing more precisely with prefixes to be more conservative about unreachability in this example, |
@adriaanm said: |
@adriaanm said: here's what i've been experimenting with using :power in the repl: scala> trait Companion {
| sealed trait Super
| object Subs {
| case object Decimal extends Super
| case object Integer extends Super
| case class Time(t: String) extends Super
| }
| }
defined trait Companion
scala>
scala> object Outer extends Companion
defined module Outer
scala>
scala>
scala> val tp = ?[Outer.Super].tpe
tp: $r.power.intp.global.Type = Outer.Super
scala> val subSyms = tp.typeSymbol.sealedDescendants
subSyms: Set[$r.power.intp.global.Symbol] = Set(object Decimal, object Integer, class Time, trait Super)
scala> val subSym = subSyms.head
subSym: $r.power.intp.global.Symbol = object Decimal
scala>
scala> tp.prefix.memberType(subSym.owner).memberType(subSyms.head)
res1: $r.power.intp.global.Type = Outer.Subs.type#Decimal.type
Outer.Subst.Decimal is closer to the type we should for the sealed descendant of Outer.Super -- currently we use Companion.Subst.Decimal... |
@retronym said: |
@adriaanm said: |
@retronym said: |
@retronym said: |
@retronym said: |
@retronym said: :power
val u = rootMirror.universe; import u._, language._, intp.deconstruct.show
def show(t: Type) {println(t); println(show(t))}
class C[T] {
sealed trait F[A <: T]
object X {
object S1 extends F[T]
}
class S2 extends F[T]
}
object O extends C[Int] {
def foo(f: F[Int]) = f match { case X.S1 => }
class S3 extends F[Int]
}
def subType(base: Symbol, sub: Symbol, baseType: Type) = {
val subTpe = sub.tpeHK
val widenNarrow = subTpe.map(_.widen.narrow)
val clazz = subTpe.baseType(base).typeSymbol.owner
val pre = baseType.prefix
val seen = widenNarrow asSeenFrom (baseType.prefix, clazz)
val result = seen.widen
def tpToString(t: Type) = t.toString.replaceAllLiterally("$iw.", "")
def p(label: String)(t: Type) = println(s"$label: ${tpToString(t)}")
println(s"subtype(base = $base, sub = $sub, baseType = ${tpToString(baseType)}")
println(s"(${tpToString(widenNarrow)}).asSeenFrom(${tpToString(pre)}, $clazz) = ${tpToString(seen)}")
p("result")(result)
result
}
val S1 = typeOf[c.X.S1.type forSome { val c: C[_] }].typeSymbol.tpeHK
val S2 = typeOf[O.S2].typeSymbol.tpeHK
val S3 = typeOf[O.S3].typeSymbol.tpeHK
val F = typeOf[c.F[_] forSome { val c: C[_] }].typeSymbol.tpeHK
val fTpe = typeOf[O.type].decl(newTermName("foo")).paramss.head.head.tpe
subType(F.typeSymbol, S1.typeSymbol, fTpe)
subType(F.typeSymbol, S2.typeSymbol, fTpe)
subType(F.typeSymbol, S3.typeSymbol, fTpe) |
@retronym said: retronym/scala@scala:2.10.x...retronym:ticket/6146 Waiting for: https://scala-webapps.epfl.ch/jenkins/job/scala-checkin-manual/797/console |
@retronym said: |
@paulp said: |
@retronym said: |
@paulp said: |
@paulp said: |
In the following pattern matching scenario, the compiler for Scala 2.10.0-M6 emits the warning message "unreachable code". That warning is not emitted in Scala 2.9.2. Furthermore, a simple test shows the case is still reached correctly.
The warning:
A test:
The text was updated successfully, but these errors were encountered: