Closed giacomocavalieri closed 2 months ago
A bit unrelated, but should we update the Expected one of:
message to remove the if block
expectation? I noticed it in your example error message.
Nice catch! I'll open a separate issue for that
Thanks folks
I'd like to make an attempt at solving this! 🤞
Thank you!
I've gotten to a point where I'm getting a nice error message for a valid-looking function call:
error: Syntax error
┌─ /src/parse/error.gleam:3:18
│
3 │ const wib: Int = wibble()
│ ^^^^^^^^ Functions can only be called within other functions
Now the question I'm trying to figure out is what to show when there's an invalid-looking function call. Right now I have
error: Syntax error
┌─ /src/parse/error.gleam:3:25
│
3 │ const wib: Int = wibble(&)
│ ^ I can't figure out what to do with this character
Hint: Is it a typo?
This matches the error message we get with incorrect function calls generally (eg let a = foo(&bar)
), but I don't know if it should. We'd first be telling the user that their function-call syntax is wrong, and after they fix it, we'll tell them they can't call functions here anyway.
An alternative might be to assume that everything from (
until a syntax error is an attempt at a function call, and we'd show something like
error: Syntax error
┌─ /src/parse/error.gleam:3:18
│
3 │ const wib: Int = wibble(foo, &bar)
│ ^^^^^^^^^^^^^ Functions can only be called within other functions
Any preferences?
Let's leave it as erroring on the first syntax error (in this case the &
) as that's what we do everywhere else, and it's not a mistake we've seen people make.
This snippet of code results in this error message:
I think that's because the compiler sees it as:
And not as a function call
Another example is when you wrap the function call in a constructor/list/etc: