scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

patmat does not consider that it is exhaustive even if it has wildcard arm #12874

Closed KisaragiEffective closed 9 months ago

KisaragiEffective commented 9 months ago

Reproduction steps

Scala version: 2.13.12

  1. checkout https://github.com/KisaragiEffective/scala-match-on-huge-enum or https://github.com/KisaragiEffective/match-on-huge-enum-sealed-trait
  2. just compile

Problems

sbt:match-on-huge-enum> compile
[info] compiling 1 Scala source and 1 Java source to /private/tmp/scala-match-on-huge-enum/target/scala-2.13/classes ...
[warn] /private/tmp/scala-match-on-huge-enum/src/main/scala/Hello.scala:5:5: Cannot check match for unreachability.
[warn] The analysis required more space than allowed.
[warn] Please try with scalac -Ypatmat-exhaust-depth 40 or -Ypatmat-exhaust-depth off.
[warn]     h match {
[warn]     ^
[warn] 1 deprecation (since 2.13.0); re-run with -deprecation for details
[warn] two warnings found
[success] Total time: 163 s (02:43), completed Sep 17, 2023 10:14:55 PM

Problem

The current implementation tries to find counter examples. However, if the match has wildcard arm, there's no such counter-examples (since wildcard catch all).

eed3si9n commented 9 months ago

Here's my PR for it - https://github.com/scala/scala/pull/10552