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

Class members hidden by recursive modules #5703

Closed
vicuna opened this issue Jul 27, 2012 · 2 comments
Closed

Class members hidden by recursive modules #5703

vicuna opened this issue Jul 27, 2012 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Jul 27, 2012

Original bug ID: 5703
Reporter: cgillot
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:16:26Z)
Resolution: won't fix
Priority: normal
Severity: minor
Target version: later
Category: typing
Tags: recmod
Monitored by: mandrykin

Bug description

I have a class hierarchy, each class being wrapped in its own module.

When using regular modules, everything compiles just fine ; but recursive modules trigger typing failure.

$ cat test.ml
module rec Ma : sig
class a : int -> object
method as_a : int
method z : int
end
end = struct
class a x = object(this)
method as_a : int = x
method z : int = 50
end
end
and Mb : sig
class b : int -> object
method as_b : int
inherit Ma.a
end
end = struct
class b =
let z = 50 in
fun x -> object(this)

method as_b : int = x
inherit Ma.a z as a

end
end
and Mc : sig
class c : int -> object
method as_c : int
inherit Mb.b
end
end = struct
class c =
let u = 42 in
fun x -> object(this)

method as_c : int = x
inherit Mb.b u as b

end
end
$ ocamlc test.ml
File "test.ml", line 31, characters 6-129:
Error: Signature mismatch:
...
Class declarations do not match:
class c :
int ->
object
method as_a : int
method as_b : int
method as_c : int
method z : int
end
does not match
class c : int -> object method as_b : int method as_c : int end
The public method as_a cannot be hidden
The public method z cannot be hidden

This error never appears with regular modules (even with explicit signatures) ; and this only happens when there are at least 3 classes.

Additional information

Ocaml version : trunk, revision 12787

File attachments

@vicuna
Copy link
Author

vicuna commented Nov 2, 2015

Comment author: mandrykin

Also bumped into this issue in PPX generated code. It can be worked around by inheriting from a common class type containing all method signatures listed in all the modules. Also attached a minimal example.

@vicuna
Copy link
Author

vicuna commented Nov 5, 2015

Comment author: @garrigue

This comes from the fact recursive modules are supposed to be typable in any order, just like if you compare

let f x = ...
let g x = ...
let h x = ...

and

let rec f x = ...
and g x = ...
and h x = ...

Recursive modules are both stronger (you can refer to all other modules) and weaker (these references carry less information).
For let and let rec this is similar; using let rec you only have access to the monomorphic versions of the other functions.

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

No branches or pull requests

2 participants