Skip to content

Report error about wrong C-style type definition for all fields #5377

@ankddev

Description

@ankddev

Problem

Currently with following code:

pub type User {
  name: String,
  surname: String
}

Gleam gives this error:

error: Syntax error
  ┌─ C:\Users\user\projects\deps_test\src\deps_test.gleam:2:3
  │
2 │   name: String
  │   ^^^^ I was not expecting this

Each custom type variant must have a constructor:

pub type User {
  User(
    name: String,
  )
}

As you see, it says only about one field, which is wrong, I think.

Desired behaviour

It should say about all fields in the error.

Motivation

Firstly, this will improve DX, since user will see full error.
Secondly, this will allow implementation of #3479, which is blocked by this.

Possible solution

I don't know, if this is possible inside parser, since it's fault tolerance skips the entire expression, I think. In case it's possible, we need to say about each field in error.

Things to consider

  1. Is it possible in parser?
  2. How to display errors about each field (just one I was not expecting this or for each one?)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions