Skip to content

match may not be exhaustive warning since Scala 3.7 #13440

@xuwei-k

Description

@xuwei-k

build.sbt

enablePlugins(PlayScala)

scalaVersion := "3.7.2"

conf/routes

GET  /aaa/*file  controllers.Assets.versioned(path="/public/aaa", file: Asset)

GET  /bbb/*file  controllers.Assets.versioned(path="/public/bbb", file: Asset)

project/build.properties

sbt.version=1.11.3

project/plugins.sbt

addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.8")

output

[warn] my-example-project/conf/routes:1:1: match may not be exhaustive.
[warn] 
[warn] It would fail on pattern case: (_, _)
[warn] GET  /aaa/*file  controllers.Assets.versioned(path="/public/aaa", file: Asset)
[warn] one warning found

output with set sourcePositionMappers := Nil

[warn] -- [E029] Pattern Match Exhaustivity Warning: my-example-project/target/scala-3.7.2/routes/main/controllers/ReverseRoutes.scala:22:6 
[warn] 22 |      (path: @unchecked, file: @unchecked) match {
[warn]    |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn]    |      match may not be exhaustive.
[warn]    |
[warn]    |      It would fail on pattern case: (_, _)
[warn]    |
[warn]    | longer explanation available when compiling with `-explain`

generated code

  def versioned(path:String, file:Asset): Call = {
    
      (path: @unchecked, file: @unchecked) match {
      
        // @LINE:1
        case (path, file) if path == "/public/aaa" =>
          implicit lazy val _rrc = new play.core.routing.ReverseRouteContext(Map(("path", "/public/aaa"))); _rrc
          Call("GET", _prefix + { _defaultPrefix } + "aaa/" + implicitly[play.api.mvc.PathBindable[Asset]].unbind("file", file))
      
        // @LINE:3
        case (path, file) if path == "/public/bbb" =>
          implicit lazy val _rrc = new play.core.routing.ReverseRouteContext(Map(("path", "/public/bbb"))); _rrc
          Call("GET", _prefix + { _defaultPrefix } + "bbb/" + implicitly[play.api.mvc.PathBindable[Asset]].unbind("file", file))
      
      }
    
    }

note

/**
* Reverse parameters for matching
*/
def reverseMatchParameters(params: Seq[(Parameter, Int)], annotateUnchecked: Boolean): String = {
val annotation = if (annotateUnchecked) ": @unchecked" else ""
params.map(x => safeKeyword(x._1.name) + annotation).mkString(", ")
}

Welcome to Scala 2.13.16 (OpenJDK 64-Bit Server VM, Java 21.0.7).
Type in expressions for evaluation. Or try :help.

scala> def f(x: Int, y: Int) = (x: @unchecked, y: @unchecked) match {
     |   case (1, 2) => 3
     | }
def f(x: Int, y: Int): Int
Welcome to Scala 3.6.4 (21.0.7, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                             
scala> def f(x: Int, y: Int) = (x: @unchecked, y: @unchecked) match {
     |   case (1, 2) => 3
     | }
def f(x: Int, y: Int): Int
Welcome to Scala 3.7.2 (21.0.7, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                             
scala> def f(x: Int, y: Int) = (x: @unchecked, y: @unchecked) match {
     |   case (1, 2) => 3
     | }
1 warning found
-- [E029] Pattern Match Exhaustivity Warning: ----------------------------------
1 |def f(x: Int, y: Int) = (x: @unchecked, y: @unchecked) match {
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                        match may not be exhaustive.
  |
  |                        It would fail on pattern case: (_, _)
  |
  | longer explanation available when compiling with `-explain`
def f(x: Int, y: Int): Int
                                                                                                                                             
scala> def f(x: Int, y: Int) = ((x, y): @unchecked) match {
     |   case (1, 2) => 3
     | }
def f(x: Int, y: Int): Int

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions