Skip to content

Exhaustivity checks are incorrect with tuple patterns bigger than 22 #16186

Closed
@Sporarum

Description

@Sporarum

Compiler version

3.2.0 / 3.2.1-RC2

Minimized code and Output

val x = 42
val tup23 = (x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x)

tup23 match {  
// ^ warning: match may not be exhaustive (wrong)
  case (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => "Tuple Pattern"
} // "Tuple Pattern"

https://scastie.scala-lang.org/Sporarum/a3AOPPg2TmGhpjwxjxyrSA/199

The warning recommends do add a case _: ..., where ... is what I pasted into the RHS of Tup23 below:

val x = 42
val tup23 = (x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x)

type Tup23 = *:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,EmptyTuple]]]]]]]]]]]]]]]]]]]]]]]

tup23 match {
  case (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => "Tuple Pattern"
  // ^ warning: Unreachable case (wrong)
  case _: Tup23                                                              => "Explicit type"
} // "Tuple Pattern"

https://scastie.scala-lang.org/Sporarum/a3AOPPg2TmGhpjwxjxyrSA/200

Expectation

The tupled pattern is both exhaustive and reachable, it should behave as the version with only 22 wildcards does:
https://scastie.scala-lang.org/Sporarum/a3AOPPg2TmGhpjwxjxyrSA/195

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions