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

Error message missing information about type inclusion #10399

Closed
jctis opened this issue May 6, 2021 · 6 comments
Closed

Error message missing information about type inclusion #10399

jctis opened this issue May 6, 2021 · 6 comments

Comments

@jctis
Copy link

jctis commented May 6, 2021

Hi,

This looks like a bug in the error message:

$ cat foo.ml

type t = < x : int >

class c = object method x = 3 method y = true end

let o = new c
$ cat foo.mli
type t = < x : int >

class c : object method x : int method y : bool end

val o : t
$ ocamlc -c foo.mli && ocamlc -c foo.ml
File "foo.ml", line 1:
Error: The implementation foo.ml does not match the interface foo.cmi:
       Values do not match: val o : c is not included in val o : t
       File "foo.mli", line 5, characters 0-9: Expected declaration
       File "foo.ml", line 6, characters 4-5: Actual declaration
$

I guess I understand why type c is not included in t. However, the last two lines are a bit confusing since the Expected declaration as well as the Actual declaration are empty. I would expect the compiler to tell me the method y cannot be hidden in the type of o.

Yours,

Judicaël Courant

@gasche
Copy link
Member

gasche commented May 6, 2021

I don't see a bug here:

  • the locations reported appear to be correct, they point to the lines let o = ... (in foo.ml) and val o : ... (in foo.mli)
  • the type of o is a subtype of t, but in OCaml subtyping is not inferred, you have to use an explicit cast

You could fix foo.ml with let o = (new c :> t).

$ ocaml
# #use "foo.ml";;
type t = < x : int >
class c : object method x : int method y : bool end
val o : c = <obj>
# let o' = (o :> t);;
val o' : t = <obj>

does that make sense?

@jctis
Copy link
Author

jctis commented May 6, 2021

You are right, I overlooked what the compiler pointed at.

I however expected a more informative message: I would like the compiler to tell me why c is not included in t, more precisely I would like it to tell me that row y of c is missing in t (of course my example is trivial, but the one I stumbled upon was more complex). That is what the compiler does when you incorrectly use subtyping for modules:

$ cat barfoo.ml 

module X(Y: sig val x : int val y : int end) = struct end

module Z = X(struct let x = 3 end)
  
$ ocamlc -c barfoo.ml 
File "barfoo.ml", line 4, characters 13-33:
4 | module Z = X(struct let x = 3 end)
                 ^^^^^^^^^^^^^^^^^^^^
Error: Signature mismatch:
       Modules do not match:
         sig val x : int end
       is not included in
         sig val x : int val y : int end
       The value `y' is required but not provided
       File "barfoo.ml", line 2, characters 28-39: Expected declaration

@lpw25
Copy link
Contributor

lpw25 commented May 6, 2021

#10170 and it's incoming follow-up PR should support that

@jctis
Copy link
Author

jctis commented May 6, 2021

Indeed. Thanks!

@antalsz
Copy link
Contributor

antalsz commented May 10, 2021

Hi @jctis – the new PR #10407 should address this once it's merged. I've added this particular error as a test case (testsuite/tests/typing-modules/pr10399.ml) so that we can see this :-)

@jctis
Copy link
Author

jctis commented May 11, 2021

Hi @antalsz
The message in your test case is much more informative. Thanks :-)

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

4 participants