Skip to content

bug(patmatch/namedTuple): Exhaustive match checking on type-mapped NamedTuple appears to be broken #23621

@ruslanSorokin

Description

@ruslanSorokin

Compiler version

scalaVersion = "3.7.1"

Checked with Scala CLI version: 1.8.4 Scala version (default): 3.7.1 via //> using scala 3.nightly - the same thing

Minimized code

//> using scala 3.7.1

import NamedTuple.{
  Map as MapFields, 
  From as FieldsFrom
}

type HkdOf[T, F[_]] = MapFields[FieldsFrom[T], F]

trait Hkd[T]:
  type Of[F[_]] = HkdOf[T, F]
  inline def of[F[_]](v: HkdOf[T, F]) = v

case class User(age: Int, name: String)
object User extends Hkd[User]


def getUser(userQuery: User.Of[Option]): Unit =
  val invalidCheck = userQuery match  // must warn, that match will fail on 'case (None, _)' or 'case (_, None)'
    case (Some(age), Some(name)) => println("both")
    // case Tuple2(Some(age), Some(name)) => println("both") // must warn, that match will fail on 'case (None, _)' or 'case (_, None)'


  // val validCheckTup = (Some(123), Option(123)) match // here it does warn
  //   case (Some(a), Some(b)) => ???

  // val validCheckNTup = (age = Some(123), name = Option(123)) match // here it does warn as well
  //   case (Some(a), Some(b)) => ???


@main def main(): Unit = getUser(User.of[Option](age = Some(123), name = None))

Output

[69] Exception in thread "main" scala.MatchError: (Some(123),None) (of class scala.Tuple2)                                                                                                                             
[69]    at app.Main$package$.getUser(Main.scala:15)                                                                                                                                                                    
[69]    at app.Main$package$.main(Main.scala:20)                                                                                                                                                                       
[69]    at app.main.main(Main.scala:20)                                                                                                                                                                                

Expectation

Compiler must issue an exhaustive match warning for the first case

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions