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

Error message more helpful when having triple equals instead of double inside lambda fn #3125

Closed
hagenek opened this issue May 10, 2024 · 7 comments · Fixed by #3150
Closed
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:low

Comments

@hagenek
Copy link

hagenek commented May 10, 2024

[1,2,3] |> list.filter(fn (a) { a === 3 }) will produce an error :

error: Syntax error
  ┌─ /src/main.gleam:6:37
  │
6 │ [1,2,3] |> list.filter(fn (a) { a === 3 }) 
  │                                     ^ There must be a 'let' to bind variable to value

Hint: Use let for binding.
See: https://tour.gleam.run/basics/assignments/

@hagenek hagenek added the bug Something isn't working label May 10, 2024
@lpil lpil added help wanted Contributions encouraged good first issue Good for newcomers priority:low and removed bug Something isn't working labels May 13, 2024
@lpil
Copy link
Member

lpil commented May 13, 2024

Thank you. We don't need to have a specific === error message, but let's at least make this not show this error message in this case.

@giacomocavalieri
Copy link
Member

It could be cool to have a specific error message for this case, especially for folks used to JS:

error: Syntax error
  ┌─ /src/main.gleam:6:37
  │
6 │ [1,2,3] |> list.filter(fn (a) { a === 3 }) 
  │                                   ^^^ Did you mean `==`?

Gleam uses `==` to check for equality between two values.

@rabingaire
Copy link
Contributor

Humm, I wonder if this error message is enough?

error: Syntax error
  ┌─ /Users/rabingaire/Desktop/gleam/example/test_app/src/test_app.gleam:4:37
  │
4 │   [1,2,3] |> list.filter(fn (a) { a === 3 }) 
  │                                     ^^ This operator has no value on its right side

Hint: Remove it or put a value after it.

@giacomocavalieri
Copy link
Member

Yeah I agree that could be more than enough for all other binary operators, but in case of === in particular I think the compiler should try being a bit more helpful and show an error message like the one I showed before

@inoas
Copy link
Contributor

inoas commented May 17, 2024

Because people are so used to strictly equals why can't the formatter just kill it with fire and replace it with double equals?

@giacomocavalieri
Copy link
Member

That could also be an option, but a good error message is still required as not everyone runs the formatter

@inoas
Copy link
Contributor

inoas commented May 17, 2024

That could also be an option, but a good error message is still required as not everyone runs the formatter

100%

rabingaire added a commit to rabingaire/gleam that referenced this issue May 17, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 18, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 18, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 20, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 20, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 20, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 20, 2024
rabingaire added a commit to rabingaire/gleam that referenced this issue May 20, 2024
lpil pushed a commit that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants