Skip to content

Named tuple selector type in match means no exhaustivity #22810

Open
@som-snytt

Description

@som-snytt

Compiler version

3.7.1-RC1-bin-SNAPSHOT-nonbootstrapped-git-f0c050e

Minimized code

scala> type Person = (name: String, age: Int)
// defined alias type Person = (name : String, age : Int)

scala> val u = ("fred", 65)
val u: (String, Int) = (fred,65)

scala> val t = ("fred", 64)
val t: (String, Int) = (fred,64)

scala> val Fred: Person = t
val Fred: Person = (fred,64)

scala> ("bob", 24) match { case `u` => 0 }
1 warning found
-- [E029] Pattern Match Exhaustivity Warning: ----------------------------------
1 |("bob", 24) match { case `u` => 0 }
  |^^^^^^^^^^^
  |match may not be exhaustive.
  |
  |It would fail on pattern case: (_, _)
  |
  | longer explanation available when compiling with `-explain`
scala.MatchError: (bob,24) (of class scala.Tuple2)
  ... 33 elided

scala> Fred match { case `u` => 0 }
scala.MatchError: (fred,64) (of class scala.Tuple2)
  ... 33 elided

scala> (("bob", 24): Person) match { case (x, 48) => 0 }
scala.MatchError: (bob,24) (of class scala.Tuple2)
  ... 33 elided

scala>

Expectation

This seems like a natural thing to do, so I expect the warning.

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