gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Improve error message if importing type using the value import syntax

Open lpil opened this issue 5 months ago • 2 comments

Give a hint to say that you probably meant the type as the value does not exist

For example, if you have a module named wibble, that defines a type named One but no value called One and you write this code

import wibble.{One}

the resulting error message should suggest import wibble.{type One}

lpil avatar Feb 03 '24 13:02 lpil

I am interested in this issue and would like to know more.

Firstly I would like to understand the issue better, does it mean that in cases such as:

import gleam/io

fn say_hello(name: Str) {
  io.println(name)
}

pub fn main() {
  let name = "Gleam"
  say_hello(name)
}

The compiler instead of saying "Did you mean Int?" should say "Str doesn't exist"?

Also in this example I find it strange that when I compile I get:

error: Unknown type
  ┌─ /home/user/glem_proj/src/mod_dep.gleam:3:20
  │
3 │ fn say_hello(name: Str) {
  │                    ^^^ Did you mean `Int`?

The type `Str` is not defined or imported in this module.

When it would have been more appropriate to say: "Did you mean String?"

R3ZV avatar Mar 12 '24 21:03 R3ZV

Ah! I've updating the issue with more detail. Thank you

lpil avatar Mar 12 '24 22:03 lpil