Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005965OCamltypingpublic2013-03-28 11:062015-12-11 19:18
Assigned Tofrisch 
PlatformOSOS Version
Product Version 
Target Version4.00.2+devFixed in Version4.01.0+dev 
Summary0005965: Strange auto-reference in recursive modules in case of name conflict with a functor parameter
DescriptionUsing "module type of X" in the definition of the recursive module X is in general rejected by the type-checker:

  module rec X : sig
    module type S = module type of X (*Error on this occurence*)
  end = X
  Error: Unbound module X

It happens to somehow work when there is a name conflict with a functor parameter:

  module Conflict (X : sig type foo end) = struct
    module rec X : sig
      module type S = module type of X (* suspect occurrence *)
    end = X

The code above type-check correctly, but the output of -i is strange, and not consistent with the output of -dtypedtree (the latter being only available in the trunk).

ocamlc -i returns

  module Conflict :
    functor (X : sig end) ->
        module rec X :
            module type S = sig
              module type S = sig
                module type S = sig type foo end

Note the triple wrapping "module type S = sig module ..." which is strange.

(Reproduced on 3.12.1, 4.00.1 and trunk)

Finally, the -dtypedtree output appears to indicate instead that the suspect occurrence of X *is* understood as a self-reference. Here is the output, curated to remove some noise:

Pstr_module "Conflict/1034"
  Pmod_functor "X/1009" (Pmty_signature [ Psig_type [ foo/1008 .. ] ])
    Pmod_structure [
      Pstr_recmodule [
        (Pmty_signature [
          Psig_modtype "S/1013"
            Pmodtype_manifest (Pmty_typeof (Pmod_ident "X/1011"))
        (Pmod_constraint (Pmod_ident "X/1011")
           (Pmty_signature [
                  Psig_modtype "S/1013"
                  Pmodtype_manifest (Pmty_typeof (Pmod_ident "X/1011"))

Note that the arguments to Ptmy_typeof make reference not to the functor argument X/1009, but to the recursively bound identifier X/1011.

This bug was discovered and reported by Arthur Wendling.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
frisch (developer)
2013-04-29 17:42

Fixed in trunk, commit 13619.
gasche (administrator)
2013-04-29 20:53

Thank you, Alain !

If I understand correctly, you exactly added the first restriction of Xavier's paper on recursive modules ( [^] ), page 3, that was not necessary before the addition of "module type of" as module names did not appear in signatures (except in "open" and "with module M = .." that seems handled differently).

> The approximation phase (step 1) fails if it encounters
> one of the following situations:
> * `include module-type` in a module signature, in case `module-type`
> refers to one of the recursively-defined module identifiers `Xi` ;
> * `inherit class-type` in a class body type, in case class-type
> refers to a class component of one of the recursively-defined
> module identifiers X

- Issue History
Date Modified Username Field Change
2013-03-28 11:06 gasche New Issue
2013-04-15 12:11 lefessan Status new => confirmed
2013-04-15 12:12 lefessan Target Version => 4.00.2+dev
2013-04-29 17:42 frisch Note Added: 0009232
2013-04-29 17:42 frisch Status confirmed => resolved
2013-04-29 17:42 frisch Fixed in Version => 4.01.0+dev
2013-04-29 17:42 frisch Resolution open => fixed
2013-04-29 17:42 frisch Assigned To => frisch
2013-04-29 20:53 gasche Note Added: 0009233
2015-12-11 19:18 xleroy Status resolved => closed
2017-02-23 16:45 doligez Category OCaml typing => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker