Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005703OCamlOCaml typingpublic2012-07-27 14:262015-11-30 07:45
Reportercgillot 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version 
Target VersionlaterFixed in Version 
Summary0005703: Class members hidden by recursive modules
DescriptionI 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 InformationOcaml version : trunk, revision 12787
Tagsrecmod
Attached Files? file icon recmod_classes.ml [^] (394 bytes) 2015-11-02 15:28 [Show Content]

- Relationships

-  Notes
(0014636)
mandrykin (reporter)
2015-11-02 15:40

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.
(0014645)
garrigue (manager)
2015-11-05 07:32

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.

- Issue History
Date Modified Username Field Change
2012-07-27 14:26 cgillot New Issue
2012-07-31 13:32 doligez Status new => acknowledged
2012-07-31 13:32 doligez Target Version => 4.00.1+dev
2012-07-31 13:32 doligez Tag Attached: recmod
2012-09-21 14:52 doligez Target Version 4.00.1+dev => 4.01.0+dev
2013-08-19 14:54 doligez Target Version 4.01.0+dev => 4.02.0+dev
2014-08-18 20:22 doligez Target Version 4.02.0+dev => later
2015-11-02 15:28 mandrykin File Added: recmod_classes.ml
2015-11-02 15:40 mandrykin Note Added: 0014636
2015-11-05 07:32 garrigue Note Added: 0014645
2015-11-30 07:45 garrigue Status acknowledged => resolved
2015-11-30 07:45 garrigue Resolution open => won't fix
2015-11-30 07:45 garrigue Assigned To => garrigue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker