gleam-lang/gleam

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

Open

#3,786 opened on Nov 4, 2024

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Rust (21,417 stars) (960 forks)batch import
help wanted

Description

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 https://github.com/gleam-lang/gleam/commit/8c5834bcdc0115abeea16c7e1ee9826d42462564

~ 💜

Contributor guide