Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix PR#6410: Error message for an attempt to use a functor as a modul…

…e is confusing

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14790 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
commit 48ecf7eb15a8da64257316f5d0d15598c3abf19b 1 parent d2194b7
Jacques Garrigue authored
View
5 testsuite/tests/typing-modules/Test.ml
@@ -54,3 +54,8 @@ module type B = A with type t = u;; (* fail *)
(* PR#5815 *)
module type S = sig exception Foo of int exception Foo of bool end;;
+
+(* PR#6410 *)
+
+module F(X : sig end) = struct let x = 3 end;;
+F.x;; (* fail *)
View
5 testsuite/tests/typing-modules/Test.ml.principal.reference
@@ -29,4 +29,9 @@ Error: Signature mismatch:
Error: This variant or record definition does not match that of type u
The types for field X are not equal.
# module type S = sig exception Foo of bool end
+# module F : functor (X : sig end) -> sig val x : int end
+# Characters 0-3:
+ F.x;; (* fail *)
+ ^^^
+Error: The module F is a functor, not a structure
#
View
5 testsuite/tests/typing-modules/Test.ml.reference
@@ -29,4 +29,9 @@ Error: Signature mismatch:
Error: This variant or record definition does not match that of type u
The types for field X are not equal.
# module type S = sig exception Foo of bool end
+# module F : functor (X : sig end) -> sig val x : int end
+# Characters 0-3:
+ F.x;; (* fail *)
+ ^^^
+Error: The module F is a functor, not a structure
#
View
12 typing/typetexp.ml
@@ -51,6 +51,7 @@ type error =
| Unbound_cltype of Longident.t
| Ill_typed_functor_application of Longident.t
| Illegal_reference_to_recursive_module
+ | Access_functor_as_structure of Longident.t
exception Error of Location.t * Env.t * error
exception Error_forward of Location.error
@@ -189,7 +190,14 @@ let rec narrow_unbound_lid_error : 'a. _ -> _ -> _ -> _ -> 'a =
in
begin match lid with
| Longident.Lident _ -> ()
- | Longident.Ldot (mlid, _) -> check_module mlid
+ | Longident.Ldot (mlid, _) ->
+ check_module mlid;
+ let md = Env.find_module (Env.lookup_module mlid env) env in
+ begin match Env.scrape_alias env md.md_type with
+ Mty_functor _ ->
+ raise (Error (loc, env, Access_functor_as_structure mlid))
+ | _ -> ()
+ end
| Longident.Lapply (flid, mlid) ->
check_module flid;
check_module mlid;
@@ -989,6 +997,8 @@ let report_error env ppf = function
fprintf ppf "Ill-typed functor application %a" longident lid
| Illegal_reference_to_recursive_module ->
fprintf ppf "Illegal recursive module reference"
+ | Access_functor_as_structure lid ->
+ fprintf ppf "The module %a is a functor, not a structure" longident lid
let () =
Location.register_error_of_exn
View
1  typing/typetexp.mli
@@ -63,6 +63,7 @@ type error =
| Unbound_cltype of Longident.t
| Ill_typed_functor_application of Longident.t
| Illegal_reference_to_recursive_module
+ | Access_functor_as_structure of Longident.t
exception Error of Location.t * Env.t * error
Please sign in to comment.
Something went wrong with that request. Please try again.