Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False exhaustivity warning when unapply return type is a tuple defined using *: #22355

Open
eejbyfeldt opened this issue Jan 13, 2025 · 1 comment

Comments

@eejbyfeldt
Copy link

Compiler version

3.6.2

Minimized code

object Test {
  sealed trait Expr[T]

  case class Person(name: String, age: Int)
  object PP {
    def unapply(e: Expr[Person]): String *: Int *: EmptyTuple = ???
  }

  val expr: Expr[Person] = ???
  expr match {
    case PP(str, _) => ???
  }
}

Output

-- [E029] Pattern Match Exhaustivity Warning: scala3_bug.scala:10:2 
10 |  expr match {
   |  ^^^^
   |  match may not be exhaustive.
   |
   |  It would fail on pattern case: PP()
   |------------------------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   | There are several ways to make the match exhaustive:
   |  - Add missing cases as shown in the warning
   |  - If an extractor always return Some(...), write Some[X] for its return type
   |  - Add a case _ => ... at the end to match all remaining cases
    ------------------------------------------------------------------------------------------
1 warning found

Expectation

The code should compile without warnings.

@eejbyfeldt eejbyfeldt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2025
@eejbyfeldt
Copy link
Author

If the unapply is changed to

    def unapply(e: Expr[Person]): (String, Int) = ???

the warnings goes away. Also if the code is changed to do a match on Person instead of Expr[Person] like

object Test {
  case class Person(name: String, age: Int)
  object PP {
    def unapply(e: Person): String *: Int *: EmptyTuple = ???
  }

  val expr: Person = ???
  expr match {
    case PP(str, _) => ???
  }
}

then there is also no warning.

@eejbyfeldt eejbyfeldt changed the title False exhaustivity warning when returning tuple using *: False exhaustivity warning when unapply return type is a tuple defined using *: Jan 13, 2025
@Gedochao Gedochao added area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants