Skip to content

#13702 error messages: specialized error messages for non-functors - #13865

Merged
Octachron merged 5 commits into
ocaml:trunkfrom
Octachron:err_modules_are_not_functor_bis
Mar 21, 2025
Merged

#13702 error messages: specialized error messages for non-functors#13865
Octachron merged 5 commits into
ocaml:trunkfrom
Octachron:err_modules_are_not_functor_bis

Conversation

@Octachron

Copy link
Copy Markdown
Member

As reported in #13702, functors appearing in a context where non-functor where expected, for instance

module Int_set: sig include Set.S end = Set.Make

are handled by the generic functor parameters mismatch error message:

Error: Signature mismatch:
      Modules do not match:
        (Ord : Set.OrderedType) -> ...
      is not included in
         -> ...
      An extra argument is provided of module type Set.OrderedType

which is not easy to decipher.

This PR proposes to specialize the error message to reduce it to a simpler

Error: Signature mismatch:
       This module should not be a functor, a signature was expected.
       Hint: Did you forget to apply the functor?

with a variant when the expected type is incompatible with the body of the functor

module Int_set: sig type x end = Set.Make
      This module should not be a functor, a signature was expected.
      Moreover, the type of the functor body is incompatible with the
      expected module type.

The reverse situation of structure appearing where a functor was expected is handled symmetrically

module M: () -> sig end = Int
Error: Signature mismatch:
      This module should not be structure, a functor was expected.

without the symmetrical hint of suggesting adding abstractions, which does not seems likely to be correct.

@gasche

gasche commented Mar 14, 2025

Copy link
Copy Markdown
Member

I think we should iterate a bit on the proposed message in the first case.

This module should not be a functor, a signature was expected.

First, I think that you mean that a structure was expected, right?

Second, I'm worried that the wording "This module should not be a functor" could be confusing to users which use "module" as a synonym for "structure". I would write simply:

You provided a functor, but a structure was expected.

or maybe a "plain structure" or a "(non-functor) structure" or a "(non-parametrized) structure".

@Octachron

Copy link
Copy Markdown
Member Author

You are right that structure will be clearer.

For your second point, I believe that

This module should not be a functor, but a structure

is clear even for people that doesn't make a clear distinction between functors and structures, or use module as a convenient abbreviation for structure. After the all, the important information is should not be a functor.

@Octachron

Copy link
Copy Markdown
Member Author

I have updated the wording; and removed an unreachable code path for abstract module types.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants