Skip to content

Using an invalid type alias reports cascading errors #6072

Description

@RevolvingMadness

The following code:

pub type UnknownTypeAlias = UnknownType

pub type UsageOfUnknownTypeAlias = UnknownTypeAlias

Produces the error:

error: Unknown type
  ┌─ /src/main.gleam:1:29
  │
1 │ pub type UnknownTypeAlias = UnknownType
  │                             ^^^^^^^^^^^

The type `UnknownType` is not defined or imported in this module.

error: Unknown type
  ┌─ /src/main.gleam:3:36
  │
3 │ pub type UsageOfUnknownTypeAlias = UnknownTypeAlias
  │                                    ^^^^^^^^^^^^^^^^

The type `UnknownTypeAlias` is not defined or imported in this module.

I would expect the first error to be reported as the type UnknownType really doesn't exist. However with the second error, I wouldn't expect it to be reported to the user until they get the previous error fixed to prevent cascading errors.

Interestingly enough:

pub type UnknownTypeAlias = UnknownType

pub type UnknownTypeAlias {}

reports

error: Duplicate type definition
  ┌─ /src/main.gleam:1:1
  │
1 │ pub type UnknownTypeAlias = UnknownType
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redefined here
  ·
5 │ pub type UnknownTypeAlias {}
  │ ------------------------- First defined here

The type `UnknownTypeAlias` has been defined multiple times.
Names in a Gleam module must be unique so one will need to be renamed.

which acknowledges that the alias UnknownTypeAlias has already been defined which contradicts

error: Unknown type
  ┌─ /src/main.gleam:3:36
  │
3 │ pub type UsageOfUnknownTypeAlias = UnknownTypeAlias
  │                                    ^^^^^^^^^^^^^^^^

The type `UnknownTypeAlias` is not defined or imported in this module.
Tested on the Gleam Playground with Gleam version 1.17.0 and on Arch Linux with Gleam version 1.18.0

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