-
-
Notifications
You must be signed in to change notification settings - Fork 800
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
Friendly error when using multiple spreads #4265
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a snapshot test for the error please so we can see what it looks like 🙏
ParseErrorType::ListSpreadWithAnotherSpread => ( | ||
"I wasn't expecting a spread here", | ||
vec![ | ||
"Hint: use list.append(list1, list2) to join two lists.".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we want to recommend this, it's normally the wrong thing to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I guess it is likely that the problem is modeled poorly. Perhaps we can add that as a comment, or suggest a common "pattern" to model such problems better.
On the other hand, you could argue that it is still helpful for newcomers. You have to type [..xs, ..ys]
to get the recommendation, so I think it is pretty clearly what you are trying to do.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't want to people to append lists, so helping them to do it would be counterproductive.
c7898c6
to
1eb6000
Compare
I didn't know about snapshot testing - that's cool! I've added the test. |
┌─ /src/parse/error.gleam:5:13 | ||
│ | ||
5 │ [..xs, 4, ..ys] | ||
│ ^^ I wasn't expecting a spread here | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing to me, the spread there is technically correct, the problem is there's a prior spread that shouldn't have been there. Maybe it could be pointing to the one that is not last and highlight how there can only be one at the end of the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the error at anything that follows the first spread would be fine and possibly easier to implement. The error can say that the spread must be the last thing in the list.
┌─ /src/parse/error.gleam:5:13 | ||
│ | ||
5 │ [..xs, 4, ..ys] | ||
│ ^^ I wasn't expecting a spread here | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the error at anything that follows the first spread would be fine and possibly easier to implement. The error can say that the spread must be the last thing in the list.
location: SrcSpan { start: 39, end: 41 }, | ||
} | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the two unit tests please 🙏
Thank you! |
This was unexpected to me, so figured other new gleamers could trip over it as well
(and an excuse to play with the compiler :))