Skip to content

Hint for TS-style return value type annotation #4984

@ankddev

Description

@ankddev

Someone coming from TypeScript can write following code:

import gleam/io

pub fn main(): Nil {
  io.println("Hello from test_gleam!")
}

In this case compiler gives this unhelpful message:

error: Syntax error
  ┌─ C:\Users\user\projects\test_gleam\src\test_gleam.gleam:3:14
  │
3 │ pub fn main(): Nil {
  │              ^ I was not expecting this

Found `:`, expected one of:
- An import, const, type, or function.

I think that it would be better if error message will be something like:

error: Syntax error
  ┌─ C:\Users\user\projects\test_gleam\src\test_gleam.gleam:3:14
  │
3 │ pub fn main(): Nil {
  │              ^ I was not expecting this

Found `:`, expected one of:
- An import, const, type, or function.
Hint: Maybe you meant to write return value type annotation?
Return type annotations are written using `->`, not `:`

If this is wanted feature, I can try to work on this.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions