Closed
Description
Compiler version
3.1.2-RC1, 3.1.3-RC1-bin-20220201-ef25672-NIGHTLY
Minimized code
@main def Test =
val it = 42
42L match
case `it` => println("pass")
case _ => println("fail")
Output
sbt:reach> run
[info] compiling 1 Scala source to /tmp/reach/target/scala-3.1.2-RC1/classes ...
[warn] -- [E030] Match case Unreachable Warning: /tmp/reach/reach.scala:4:9 -----------
[warn] 4 | case `it` => println("pass")
[warn] | ^^^^
[warn] | Unreachable case
[warn] one warning found
[info] done compiling
[info] running Test
pass
This issue came up while updating fs2 in the community build in #14395, where -Xfatal-warnings is in use. Can reproduce in fs2 like so:
$ git clone https://github.com/typelevel/fs2.git && cd fs2
$ git rev-parse HEAD
cd280871b516243d120bcd16090f7cb51daddb27
$ sbt "++3.1.2-RC1 coreJVM/compile"
[info] welcome to sbt 1.6.1 (AdoptOpenJDK Java 1.8.0_292)
[info] loading global plugins from /home/tgrigg/.sbt/1.0/plugins
[info] loading settings for project fs2-build from plugins.sbt ...
[info] loading project definition from /tmp/fs2/project
[info] loading settings for project root from build.sbt ...
[info] resolving key references (16343 settings) ...
[info] set current project to root (in build file:/tmp/fs2/)
[info] Setting Scala version to 3.1.2-RC1 on 16 projects.
[info] Reapplying settings...
[info] set current project to root (in build file:/tmp/fs2/)
[info] compiling 37 Scala sources to /tmp/fs2/core/jvm/target/scala-3.1.2-RC1/classes ...
[warn] -- [E030] Match case Unreachable Warning: /tmp/fs2/core/shared/src/main/scala/fs2/Stream.scala:2116:21
[warn] 2116 | case `concurrency` => channel.close *> end.complete(()).void
[warn] | ^^^^^^^^^^^^^
[warn] | Unreachable case
[warn] one warning found
where the relevant code is:
val concurrency = if (maxConcurrent == Int.MaxValue) Int.MaxValue else maxConcurrent + 1
val action =
(
Semaphore[F2](concurrency.toLong),
Channel.bounded[F2, F2[Either[Throwable, O2]]](concurrency),
Deferred[F2, Unit],
Deferred[F2, Unit]
).mapN { (semaphore, channel, stop, end) =>
val releaseAndCheckCompletion =
semaphore.release *>
semaphore.available.flatMap {
case `concurrency` => channel.close *> end.complete(()).void
case _ => ().pure[F2]
}
Note that here the type of concurrency
is Int
and semaphore.available
is F2[Long]
.
Works as expected on 3.1.1 and earlier
Expectation
No warning.