Skip to content

Error's type printing: Consider only annotated type variables for the current definition rather than the whole module #3786

Open
@yoshi-monster

Description

@yoshi-monster

I talked about this on Discord with Gears, and he thinks this is actually a bug worth reporting 😄

When the compiler introduces auto-generated type variable names for reporting errors (and in the LSP), 1.5.1 always starts at a. The nightly release of the compiler instead seems to reserve explicitly annotated type variable names used elsewhere in the module. This means that the names generated will not usually start with a, but rather with the next free letter.

import gleam/io

type Wibble(a, b, c, d, e, f, g) {
  Wibble(value: a)
}

fn wibble(value: h) {
  io.debug(value)
  Nil
}

fn wobble() {
  let x: List(i) = []
  wibble(x)
  wibble(fn() -> List(j) { [] })
}

pub fn main() {
  let x: Nil = []
}

produces:

error: Type mismatch
   ┌─ C:\Users\joshua\Documents\globe\src\globe.gleam:19:16
   │
18 │   let x: Nil = []
   │                ^^

Expected type:

    Nil

Found type:

    List(k)

type variables a..j are reserved because of the other usages above.

I ran git bisect and figured out this was introduced in 8c5834b

~ 💜

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions