summaryrefslogtreecommitdiff
path: root/typing
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2014-05-14 15:07:13 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2014-05-14 15:07:13 +0000
commit3ffa399b3714c7ce084d05415a0faa0a6c976aa3 (patch)
tree03d8fb0cfd46dd22adfbf3e88fa85d502c64232a /typing
parentfb8aecbf249e57ccdcd70cc0482f05a5307cf7f6 (diff)
downloadocaml-3ffa399b3714c7ce084d05415a0faa0a6c976aa3.tar.gz
Use a nominal datatype for CamlinternalFormat.format6
This should make the type-checking of formats simpler and more robust: instead of trying to find a pair as previously, we can now use the path of the format6 type directly. A nice side-effect of the change is that the internal definition of formats (as a pair) is not printed in error messages anymore. Because format6 is in fact defined in the CamlinternalFormatBasics submodule of Pervasives, and has an alias at the toplevel of Pervasives, error messages still expand the definition: > Error: This expression has type > ('a, 'b, 'c, 'd, 'd, 'a) format6 = > ('a, 'b, 'c, 'd, 'd, 'a) CamlinternalFormatBasics.format6 > but an expression was expected of type ... Passing the option `-short-paths` does avoid this expansion and returns exactly the same error message as 4.01: > Error: This expression has type ('a, 'b, 'c, 'd, 'd, 'a) format6 > but an expression was expected of type ... (To get this error message without -short-paths, one would need to define format6 directly in Pervasives; but this type is mutually recursive with several GADT types that we don't want to add in the Pervasives namespace unqualified. This is why I'll keep the alias for now.) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14868 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'typing')
-rw-r--r--typing/typecore.ml20
1 files changed, 7 insertions, 13 deletions
diff --git a/typing/typecore.ml b/typing/typecore.ml
index b6cb5e4124..ca8c6c3f54 100644
--- a/typing/typecore.ml
+++ b/typing/typecore.ml
@@ -1778,21 +1778,15 @@ and type_expect_ ?in_function env sexp ty_expected =
end
| Pexp_constant(Const_string (str, _) as cst) -> (
(* Terrible hack for format strings *)
- let expected_ty = (repr (expand_head env ty_expected)).desc
- and fmt6_path = get_camlinternalFormat_path env "format6"
- and fmt_path = get_camlinternalFormat_path env "fmt" in
- let is_format = match expected_ty, fmt6_path, fmt_path with
- | Tconstr(path, _, _), Some pf6, _ when Path.same path pf6 -> true
- | Ttuple [ fmt_ty; str_ty ], _, Some pf ->
- ignore (unify env str_ty Predef.type_string);
- begin match (repr (expand_head env fmt_ty)).desc with
- | Tconstr (path, _, _) when Path.same path pf -> true
- | _ -> false
- end
+ let ty_expected_desc = (repr (expand_head env ty_expected)).desc in
+ let fmt6_path = get_camlinternalFormat_path env "format6" in
+ let is_format = match ty_expected_desc, fmt6_path with
+ | Tconstr(path, _, _), Some pf6 when Path.same path pf6 -> true
| _ -> false
in
if is_format then
- let format_parsetree = { sexp with pexp_desc = type_format loc str env } in
+ let format_parsetree =
+ { sexp with pexp_desc = type_format loc str env } in
type_expect ?in_function env format_parsetree ty_expected
else
rue {
@@ -2979,7 +2973,7 @@ and type_format loc str env =
| End_of_format ->
mk_constr "End_of_format" [] in
let mk_format fmt str =
- mk_exp_loc (Pexp_tuple [ mk_fmt fmt; mk_string str ]) in
+ mk_constr "Format" [ mk_fmt fmt; mk_string str ] in
let Fmt_EBB fmt = fmt_ebb_of_string str in
let exp = { (mk_format fmt str) with pexp_loc = loc } in
let pervasives_format6_ty =