close
Skip to content

Confusing error message when signatures of functor arguments differ #14214

@bclement-ocp

Description

@bclement-ocp

Consider the following files:

  • bug.ml:

    type 'a f
    
    type 'a g
    
    module Make(X : sig
      val f : int f
    
      val g : int g
    end) = struct end
  • bug.mli:

    type 'a f
    
    type 'a g
    
    module Make(X : sig
      val f : int f
    
      val g : int
    end) : sig end

The implementation does not match the interface: there is val g : int g in the .ml file, but val g : int in the .mli file. The OCaml compiler refuses this file (the following is obtained with trunk at 1fd6eae but OCaml 5.3 and OCaml 4.14 also give a similar reason), but seems to be confused about the justification:

$ ocamlc.opt -nopervasives -nostdlib bug.mli && ocamlopt.opt -nopervasives -nostdlib -I . bug.ml
File "bug.ml", line 1:
Error: The implementation bug.ml does not match the interface bug.mli:
       In module Make:
       Modules do not match:
         (X : $S1) -> ...
       is not included in
         (X : $T1) -> ...
       Module types do not match:
         $S1 = sig val f : int f val g : int g end
       does not include
         $T1 = sig val f : int f val g : int end
       Values do not match: val f : int f is not included in val f : int f
       The type int f is not compatible with the type int f
       Type f is abstract because no corresponding cmi file was found
       in path.
       File "bug.ml", line 6, characters 2-15: Expected declaration
       File "bug.mli", line 6, characters 2-15: Actual declaration

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions