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

Confusing error message for incompatible types having the same name #340

Open
luauser32167 opened this issue Jan 30, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@luauser32167
Copy link
Contributor

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.

@vtereshkov
Copy link
Owner

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 vtereshkov changed the title Incompatible type error for the same type alias Confusing error message for incompatible types having the same name Jan 31, 2024
@vtereshkov vtereshkov added the enhancement New feature or request label Jan 31, 2024
@luauser32167
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants