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

give more descriptive error on unmatched pattern #2128

Open
KiaraGrouwstra opened this issue Dec 19, 2024 · 2 comments
Open

give more descriptive error on unmatched pattern #2128

KiaraGrouwstra opened this issue Dec 19, 2024 · 2 comments

Comments

@KiaraGrouwstra
Copy link
Contributor

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

when faced with an unmatched pattern, nickel seems to not yet give much of a hint as to where to look.

Describe the solution you'd like
give more info as to what fields of a record might not be matched.

Describe alternatives you've considered
manually comparing records

Additional context

minimum repro:

nickel> let {a,b} = {a=1} in a
error: unmatched pattern
  ┌─ <repl-input-1>:1:5
  │
1 │ let {a,b} = {a=1} in a
  │     ^^^^^^^^^^^^^
  │     │       │
  │     │       this value doesn't match any branch
  │     in this match expression
@yannham
Copy link
Member

yannham commented Dec 20, 2024

Hello,

Thanks for reporting. Good error messages are indeed important for us. Just to make sure I understand, I imagine you would like to have an additional message like the following (I added a line at the end)?

error: unmatched pattern
  ┌─ <repl-input-1>:1:5
  │
1 │ let {a,b} = {a=1} in a
  │     ^^^^^^^^^^^^^
  │     │       │
  │     │       this value doesn't match any branch
  │     in this match expression
  + Pattern expected a field `b` to be present, but it couldn't be found in the value.

So it's a bit of an implementation detail, but destructuring let <pattern> = <value> in <rest> is desugared (almost) to pattern matching <value> |> match { <pattern> => <rest>, _ => <error> }. In the general case of pattern matching, I think it can be hard to have a nice and concise explanation of why the value didn't match, because it means that none of potentially many branches did match. For example, in {a = 1} |> match { {a,b} => 0, {a,c} => 1, {a,d} => 2, 'Tag => 3, false = 4}, what reason could you give to the user? I personally think the error message is doing the best it can do: point the pattern, and let the user see why none of the branches matched.

For destructuring, since there's only one branch,we could indeed do better in theory. I'm not sure yet how hard this would be; I'll have to think about how to integrate better error reporting with the way patterns are currently compiled.

@KiaraGrouwstra
Copy link
Contributor Author

Hi there,
That's fair, yeah. Thanks for thinking along!

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

No branches or pull requests

2 participants