gleam-lang/gleam

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

Open

#3,786 建立於 2024年11月4日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)Rust (960 fork)batch import
help wanted

倉庫指標

Star
 (21,417 star)
PR 合併指標
 (平均合併 10天 19小時) (30 天內合併 69 個 PR)

描述

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

~ 💜

貢獻者指南