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

Improve enum element pattern matching diagnostics when the arity of arguments mismatch #66750

Open
hamishknight opened this issue Jun 19, 2023 · 0 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. diagnostics QoI Bug: Diagnostics Quality of Implementation pattern matching Feature: pattern matching type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Contributor

hamishknight commented Jun 19, 2023

For the following:

func foo(_ r: Result<String, Error>) {
  let _ = {
    switch r {
    case .success:
      "a"
    case .failure():
      "b"
    }
  }
}

we emit the error:

error: type '()' cannot conform to 'Error' [type_cannot_conform]
    case .failure():
          ^

The non-closure case isn't much better

func foo(_ r: Result<String, Error>) {
  switch r {
  case .success:
    break
  case .failure(): // error: tuple pattern cannot match values of the non-tuple type 'any Error'
    break
  }
}

We ought to improve the diagnostics around enum element pattern argument matching to give diagnostics comparable to existing argument list diagnostics.

rdar://72846034

@hamishknight hamishknight added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis pattern matching Feature: pattern matching labels Jun 19, 2023
@hamishknight hamishknight self-assigned this Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. diagnostics QoI Bug: Diagnostics Quality of Implementation pattern matching Feature: pattern matching type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant