Open
Description
Compiler version
scalac 3.6.3
sbt: 1.10.7 with the following options in build.sbt
:
scalacOptions ++= Seq(
"-language:strictEquality",
"-deprecation",
"-explain",
"-explain-types",
"-feature",
"-indent",
"-new-syntax",
"-print-lines",
"-unchecked",
"-Xkind-projector",
"-Xmigration",
"-source:3.7"
)
Minimized example
def f(n: Int): Option[Int] = {
if n == 0 then None else Some(n)
} ensuring (
_ match {
case Some(i) => i != 0
case None => true
}
)
Output Error/Warning message
sbt:Martin Berger> ~compile
[info] compiling 12 Scala sources to ...
[warn] -- [E030] Match case Unreachable Warning: .../Main.scala:45:9
[warn] 45 | case None => true
[warn] | ^^^^
[warn] | Unreachable case
[warn] one warning found
Note: I get this warning only when compiling with sbt
. If I compile with scalac -Wall
there is no warning!
Why this Error/Warning was not helpful
The message Unreachable case
is unhelpful because the None
case in the ensuring
construct is in fact reachable. This can easily be seen by replacing case None => true
with case None => { assert(false); true }
and call f(0)
.
Suggested improvement
I think this is a bug in the type-inferencer. I did not file a bug report, because I wasn't sure if I had not overlooked some subtle feature of the typing system.