-
Notifications
You must be signed in to change notification settings - Fork 21
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 with sealed abstract class #11457
Comments
"good first issue" because a newcomer could at least attempt to isolate it. (and once isolated, perhaps a fix would be within reach, too.) |
Sorry, I've failed to come back to minimize this, but 👍 to the good-first-issue. If anyone needs help with the mechanics of building http4s or a tutorial on what that code is doing, I'm happy to help here or on Gitter. |
This is still present in 2.13.0. |
I minimized this to sealed abstract case classes. This warns on sealed abstract class Foo(val a: String)
object Foo {
def unapply(foo: Foo): Some[String] =
Some(foo.a)
}
class Issue11457 {
val root: PartialFunction[Foo, Boolean] = {
case Foo("a") => true
case Foo("b") => false
}
} If |
Got this when trying to port http4s/rho to 2.13 with the following code :
|
Moved to 2.13.1 since this warning is emitted by default, without special compiler flags. |
I worked on a fix for the minimization, but unfortunately that doesn't fix the original issue in the http4s repo. The minimization did regress between M4 and M5, in https://github.com/scala/scala/pull/6485/files. I'm not sure if the http4s example also regressed with that change, but it seems likely. What seems special in the minimization: we are matching on a sealed abstract class with no subclasses MatchAnalysis.scala#L144-L154. Since sealed abstract types are excluded (see scala/scala@311b7de861), the domain in the patmat analyis will be empty Logic.scala#L547; I'm not sure if this violates a precondition. The following WIP fixes the minimization, but as I said earlier not the http4s example. https://github.com/scala/scala/compare/2.13.x...lrytz:t11457?expand=1 @eed3si9n do you maybe have time to take a look? |
I have just hit this issue when migrating our service to scala 2.13. Is there a workaround to make the code compile even when turning warnings into errors? |
sorry, I somehow missed this.
There's a planed feature @lrytz is working on to help there, but in the meantime maybe try silencer? - https://github.com/ghik/silencer |
Thanks for the tip, @eed3si9n. I can make our code base compile with 2.13. Since I want to disable the smallest possible number of warnings, does anyone know that the precise name of this warning is? https://docs.scala-lang.org/overviews/compiler-options/index.html |
I believe the following snippet is another way to exhibit the same bug: https://scastie.scala-lang.org/eSn923EqTFy4aIHEdp94sg sealed trait Command {
type Reply
}
final case class Create() extends Command {
type Reply = CreateReply
val reply: Reply = CreateReply()
}
final case class Set() extends Command {
type Reply = SetReply
val reply: Reply = SetReply()
}
case class CreateReply()
case class SetReply()
def process[R](command: Command { type Reply = R }): R =
command match {
case create: Create => create.reply
case set: Set => set.reply
// ^
// Warning: unreachable code
} |
we haven't succeeded in nerd-sniping anyone into attempting a fix, it seems. but we have attempted to nerd-snipe @som-snytt yet? "nerd-snipe som snytt yet": say it three times fast |
I started looking at this and took it on a jog this afternoon. Returning by Coyote Trail, I came to the same conclusion as Lukas (because I'd failed to read his comment first), namely, an extractor never matches However, in the minimization, just one case should fail to compile, as it must fail to match.
|
I will minimize this after Typelevel Summit, but filing a placeholder now.
In this snippet, the
Ok(req.body)
is falsely flagged as unreachable code.We have many similar warnings in the tests using this DSL. No warning is generated in Scala 2.12.8 or 2.11.12.
First spotted in http4s/http4s#2393.
The text was updated successfully, but these errors were encountered: