Skip to content

Match exhaustivity warning when matching scala.concurrent.duration.MILLISECONDS and more #24750

@Zschimmer

Description

@Zschimmer

Compiler version

3.8.0-RC3

Minimized code

//import java.util.concurrent.TimeUnit.{DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS, SECONDS}
import scala.concurrent.duration.*

object ScalaTest:

  def main(args: Array[String]): Unit =
    f(3.seconds)

  private def f(duration: FiniteDuration) =
    duration.unit match
      case NANOSECONDS =>
      case MICROSECONDS =>
      case MILLISECONDS =>
      case SECONDS =>
      case MINUTES =>
      case HOURS =>
      case DAYS =>

Output

Compiler emits a exhaustivity warning:

warn] -- [E029] Pattern Match Exhaustivity Warning: /Users/joa/dev/js7/js7-base/shared/src/test/scala/js7/base/utils/ScalaTest.scala:12:13 
[warn] 12 |    duration.unit match
[warn]    |    ^^^^^^^^^^^^^
[warn]    |match may not be exhaustive.
[warn]    |
[warn]    |It would fail on pattern case: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS
[warn]    |(More unmatched cases are elided)

Expectation

No warning, as with Scalac 3.7.4.

No warning is emitted when importing the TimeUnit values directly from java.util.concurrent.TimeUnit

Maybe scala.concurrrent.duration could export these values?

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions