umka-lang
umka-lang copied to clipboard
Confusing error message for incompatible types having the same name
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.
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.
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?