gleam-lang/gleam

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

Open

#3.786 geöffnet am 4. Nov. 2024

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (960 Forks)batch import
help wanted

Repository-Metriken

Stars
 (21.417 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 10T 19h) (69 gemergte PRs in 30 T)

Beschreibung

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