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

Exhaustive match option for union types #371

Closed
spamegg1 opened this issue Feb 2, 2024 · 0 comments · Fixed by scalameta/metals#6129
Closed

Exhaustive match option for union types #371

spamegg1 opened this issue Feb 2, 2024 · 0 comments · Fixed by scalameta/metals#6129
Assignees

Comments

@spamegg1
Copy link

spamegg1 commented Feb 2, 2024

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 #317

Search terms

union types pattern matching exhaustivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants