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

Unexpected type reported in type error #1794

Closed
SkySkimmer opened this issue Feb 1, 2019 · 6 comments
Closed

Unexpected type reported in type error #1794

SkySkimmer opened this issue Feb 1, 2019 · 6 comments

Comments

@SkySkimmer
Copy link

module M = struct
  type a
  let f (x:a) = x
end

type b = M.a

let _ = M.f 2

Got:

Error: This expression has type int but an expression was expected of type b

Expected:

Error: This expression has type int but an expression was expected of type M.a

In the original case b is an alias with some semantic meaning (even though as an alias it can't produce a strong guarantee) like https://github.com/coq/coq/blob/506136d60c0dcc4fc2a2ca83ef3b586fbede55a2/kernel/names.mli#L118 (and f was https://github.com/coq/coq/blob/506136d60c0dcc4fc2a2ca83ef3b586fbede55a2/kernel/names.mli#L56)

This behaviour is because of -short-paths (I guess from #1743 ?). I haven't reviewed the history of that commit but the commit message only talks about ocamlc -i, would it be possible to avoid using -short-paths for other commands (and also avoid putting it in .merlin)?

@ghost
Copy link

ghost commented Feb 4, 2019

This seems like an OCaml bug, could you report it upstream? -short-paths is in general beneficial for developers, so disabling it in Dune doesn't seem right.

@SkySkimmer
Copy link
Author

@SkySkimmer
Copy link
Author

Looks like they don't think it's a bug either

@ghost
Copy link

ghost commented Feb 4, 2019

Indeed. Looking at the example again, it doesn't look like a bug to me either. In any case, there is not much we can do in Dune.

SkySkimmer added a commit to SkySkimmer/coq that referenced this issue Mar 1, 2019
This makes it so that
~~~ocaml
module M = struct
  type a
  let f (x:a) = x
end

type b = M.a

let _ = M.f 2
~~~
We get

    Error: This expression has type int but an expression was expected of type M.a

instead of

    Error: This expression has type int but an expression was expected of type b

We want this for Coq since we have numerous aliases in this pattern,
eg module_ident = Id.t in names.

See ocaml/dune#1794
SkySkimmer added a commit to SkySkimmer/coq that referenced this issue Mar 1, 2019
This makes it so that
~~~ocaml
module M = struct
  type a
  let f (x:a) = x
end

type b = M.a

let _ = M.f 2
~~~
We get

    Error: This expression has type int but an expression was expected of type M.a

instead of

    Error: This expression has type int but an expression was expected of type b

We want this for Coq since we have numerous aliases in this pattern,
eg module_ident = Id.t in names.

See ocaml/dune#1794 https://caml.inria.fr/mantis/view.php?id=7911
@SkySkimmer
Copy link
Author

Very well then

@rgrinberg
Copy link
Member

@SkySkimmer Perhaps you could try making it a private type alias:

type b = private M.a

And then you'll have to do all the coercions explicitly. That shouldn't be so bad, if there's really a semantic meaning to your alias.

In general, you really want -short-paths as without it you will be really disappointed by the error messages, especially in the presence of wrapped libraries.

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

No branches or pull requests

2 participants