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

Confusing type error in variant pattern match #434

Open
LightAndLight opened this issue Jul 9, 2024 · 1 comment
Open

Confusing type error in variant pattern match #434

LightAndLight opened this issue Jul 9, 2024 · 1 comment
Labels
UX User experience.

Comments

@LightAndLight
Copy link
Owner

Example

$ cat test.ipso
test : Array a -> Bool
test items =
  case array.find (\_ -> false) of
    None () -> false
    Some _ -> true

$ ipso --check test.ipso
test.ipso:4:5: error: expected kind "Type", got kind "Row"
  |
4 |     None () -> false
  |     ^

The mistake is that I forgot to pass the array argument to array.find, so I'm trying to pattern match on a function Array a -> (| Some : a, None : () |).

If the scrutinee determines the type of the pattern, then the type error should be:

test.ipso:4:5: error: expected type "Array a -> (| Some : a, None : () |)", got type "(| None : (), r |)"
  |
4 |     None () -> false
  |     ^
@LightAndLight LightAndLight added the UX User experience. label Jul 9, 2024
@LightAndLight LightAndLight changed the title Confusing type error Confusing type error in variant pattern match Jan 10, 2025
@LightAndLight
Copy link
Owner Author

A similar issue:

$ cat test.ipso
fn : (| Some : a, None : () |) -> String
fn x =
  case x of
    Nothing () -> "Nothing"
    Just a -> "Just"

$ ipso --check test.ipso
test.ipso:4:5: error: expected type "(| Some : a, None : () |)", got type "(| Nothing : ?3, Some : a, None : (), ?5 |)"
  |
4 |     Nothing () -> "Nothing"
  |     ^

I think I'd expect the error to be:

test.ipso:4:5: error: expected type "(| Some : a, None : () |)", got type "(| Nothing : ?3, ?5 |)"
  |
4 |     Nothing () -> "Nothing"
  |     ^

That is to say: Nothing is not a valid constructor for this variant.

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

No branches or pull requests

1 participant