Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joshi-monster opened this issue Nov 4, 2024 · 2 comments
Labels
help wanted Contributions encouraged priority:medium

Comments

@joshi-monster
Copy link
Contributor

joshi-monster commented Nov 4, 2024

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

~ 💜

@joshi-monster joshi-monster added the bug Something isn't working label Nov 4, 2024
@GearsDatapacks
Copy link
Member

The correct behaviour here would be to only track type variable names in the current function, rather than the whole module. This would require a rework of the Names class.
This is pretty low priority as it still produces correct annotations, even if somewhat redundant ones.

@lpil lpil added help wanted Contributions encouraged priority:medium and removed bug Something isn't working labels Nov 4, 2024
@lpil lpil changed the title Nightly: Type variable names used in the module are now reserved for the whole module Error's type printing: Consider only annotated type variables for the current definition rather than the whole module Nov 4, 2024
@lpil
Copy link
Member

lpil commented Nov 4, 2024

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

3 participants