scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

Exhaustive match option for union types #371

Closed spamegg1 closed 7 months ago

spamegg1 commented 8 months ago

Is your feature request related to a problem? Please describe.

The compiler (3.3.1) seems to be aware of exhaustivity of a union type argument:

scala> trait ID
     | case class UserName(name: String) extends ID
     | case class Password(hash: Int) extends ID
// defined trait ID
// defined case class UserName
// defined case class Password

scala> def help(id: UserName | Password) = id match
     |   case UserName(name) => name
     |   // omitting the Password(hash) case on purpose
1 warning found
-- [E029] Pattern Match Exhaustivity Warning: -------------------------------------------------------------------------
1 |def help(id: UserName | Password) = id match
  |                                    ^^
  |                                    match may not be exhaustive.
  |
  |                                    It would fail on pattern case: Password(_)
  |
  | longer explanation available when compiling with `-explain`
def help(id: UserName | Password): String

But we don't get an exhaustive match option for them, like we do for enums or other matchable types: Screenshot from 2024-02-02 10-20-59

Describe the solution you'd like

Would it be possible to get match (exhaustive) option there?

Describe alternatives you've considered

(no alternatives)

Additional context

Might be relevant https://github.com/scalameta/metals-feature-requests/issues/317

Search terms

union types pattern matching exhaustivity