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 custom type pattern matching error message #4112

Open
bouzlibop opened this issue Dec 27, 2024 · 2 comments
Open

Improve custom type pattern matching error message #4112

bouzlibop opened this issue Dec 27, 2024 · 2 comments

Comments

@bouzlibop
Copy link

Context

When trying to run following:

import gleam/io

pub fn main() {
  let X = 2
  io.debug(X)
}

in the playground

One gets:

error: Unknown variable
  ┌─ /src/main.gleam:4:7
  │
4 │   let X = 2
  │       ^

The name `X` is not in scope here.

error: Unknown variable
  ┌─ /src/main.gleam:5:12
  │
5 │   io.debug(X)
  │            ^

The name `X` is not in scope here.

Maybe this error message could be improved so that it's clear that here the user tried to pattern match on a constructor which does not exsits.

Notes

This issue was discussed on the Discord server:

Danielle — 11:09
Yeah that is a slightly confusing error message to me
lpil — 11:09
What you’ve written is valid Gleam
You’re pattern matching on a custom type constructor called X, but no such constructor is in scope
We couldn’t change the error message for this niche situation without making the error message for common situation worse
Danielle — 11:11
does it saying error: Unknown variable make the most sense considering it's a pattern match?
lpil — 11:12
Unknown constructor might be clearer
Unknown value?
bouzlibop — 11:14
"You’re pattern matching on a custom type constructor called X" would be a super helpful error message 🙂
lpil — 11:14
Could you make an issue with the above conversation please
bouzlibop — 11:14
Sure 👍
lpil — 11:17
Thank you

@GearsDatapacks
Copy link
Member

So what should the error messages be in these two cases?

@lpil
Copy link
Member

lpil commented Dec 27, 2024

I think "error: Unknown constructor" and "The custom type variant constructor X is not in scope here." could be clearer

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

3 participants