umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

Confusing error message for incompatible types having the same name

Open luauser32167 opened this issue 1 year ago • 2 comments

mymod.um:

type s64 = int;
fn f*(xs: []s64): s64 {
  return xs[0];
}

main.um

import "mymod.um";
type s64 = int;
fn main() {
  var xs: []s64 = make([]s64, 10);
  mymod.f(xs); // Error main.um (5, 12): Incompatible type []s64 for parameter 1 to fn ([]s64): s64
}

Moving function f and type alias s64 from main.um to a separate module (mymod.um) results in a type error.

luauser32167 avatar Jan 30 '24 16:01 luauser32167

Because it is not a type alias, but a declaration of a new type. If you have two named types, they can only be explicitly converted to each other: mymod.f([]mymod.s64(xs)).

However, I see an issue with the confusing error message that lacks the module qualifier.

vtereshkov avatar Jan 31 '24 08:01 vtereshkov

In my opinion calling both mymod.f0() and mymod.f1() from main.um should be allowed:

mymod.um:

type s64 = int;
fn f0*(x: s64): s64 { return x + 1; }
fn f1*(xs: []s64): s64 { return xs[0] + 1; }

main.um

import "mymod.um";
type s64 = int;
fn main() {
  var x: s64 = 69;
  var xs: []s64 = make([]s64, 105);
  mymod.f0(x); // ok
  mymod.f1(xs); // error: Incompatible type...
}

From The Umka Language Reference :

Two types are equivalent if

  • ...
  • They are dynamic array types and have equivalent item types
  • ...

Maybe relaxing equivalent to compatible here?

luauser32167 avatar Feb 01 '24 13:02 luauser32167