Closed sajorobinson closed 1 month ago
Thank you!
I'm taking a look! 👀
Thank you! What do you think the error ought to be?
@lpil I think that "a record constructor" and the message contents are pretty descriptive, but I think a change in formatting could improve readability.
I'm currently working on changing this error message to look something like the following... What do you think? (Note, the expected tokens will indeed be inlined as shown.)
Expected a "}" or a record constructor
Something I noticed is the way the error is presented, it seems like it's supposed to be an unordered list of possible things it's expecting.
I think I would have interpreted its meaning more quickly if it looked like:
Expected one of:
- "}"
- A record constructor
or, if markdown unordered lists aren't desirable, something using indents like:
Expected one of:
"}"
A record constructor
Agreed; if we go with a list, there needs to be something that denotes list items (the capital "A" in "A record" is a nice touch too).
Also, I noticed that my proposed solution results in horizontal growth of the error message, though, in practice, this shouldn't be an issue. I suppose it's a matter of preference...
Seeing as this is a common mistake perhaps we could show what the correct code should be. We could use the name of the type as the name of the constructor we display
pub type User {
name: String
}
error: Syntax error
┌─ /Users/louis/src/lpil/puck/src/puck.gleam:23:3
│
23 │ name: String
│ ^^^^ I was not expecting this
Each custom type variant must have a constructor:
pub type User {
User(
name: String,
)
}
Ooo, that's a great idea 👌
I'll see if I can fold in a similar approach for other instances of unexpected tokens.
This can be closed I think!
I was having trouble creating a custom type and was having trouble understanding the error message.
I later learned I was trying to make the type incorrectly. I needed to make a constructor for it. Knowing that now, the error message makes a lot more sense, but I didn't understand it then.
The error message could possibly be improved to be clearer. Possibly:
A screenshot is below.
Thanks!