Skip to content

Confusing error message when signatures of functor arguments differ #14214

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

Activity

  1. self-assigned this
    on Sep 3, 2025
  2. Octachron commented on Sep 3, 2025

    @Octachron
    Member

    This was the result of the mechanism for higher-level error messages for functors missing some equalities between paired items. Thus inside the functor argument, the equality t(implementation)=t(interface) was missing. Moreover, since the typing environment during the inclusion check only contains the implementation-side identifiers, the error message concluded that if t(interface) was absent of the environment this was surely due to a missing cmi.

    `This is fixed in #14221.

  3. added a commit that references this issue on Sep 4, 2025
  4. Octachron commented on Sep 4, 2025

    @Octachron
    Member

    This bug will be fixed in the upcoming 5.4 release, thanks for the report !

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

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