Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 305524932db142351d1ed4a9520eb29a5f24fa7f Mon Sep 17 00:00:00 2001
- From: Octachron <octa@polychoron.fr>
- Date: Fri, 30 Jan 2015 17:50:21 +0200
- Subject: [PATCH] Warnings for using .{} without opening Bigarray
- The previous change to the index operator .{} (and friends) broke backward
- source code compatibility with the previous version of Ocaml. Program using
- these operators without opening the Bigarray module triggered an error.
- To alleviate this problem, this patch adds a temporary hack to the type
- checker to transform the corresponding errors in a warning.
- ---
- typing/typetexp.ml | 23 +++++++++++++++++++++--
- 1 file changed, 21 insertions(+), 2 deletions(-)
- diff --git a/typing/typetexp.ml b/typing/typetexp.ml
- index 523d435..e7b99bc 100644
- --- a/typing/typetexp.ml
- +++ b/typing/typetexp.ml
- @@ -239,10 +239,29 @@ let find_class env loc lid =
- check_deprecated loc decl.cty_attributes (Path.name path);
- r
- +(* With the simplification of index operators, the expression a.{..} are no longer resolved to Bigarray.Array[n].[g|s]et.
- +To ease the transition period, we catch the case where the index operators .{}/.{,}.. are not bound in the current scope and reintroduce the
- +binding with a deprecation warning. *)
- +let lookup_value_with_deprecated_indexop loc lid env =
- +let lookup_deprecated lid env =
- + match lid with
- + | Longident.Lident s -> ( match s with
- + | ".{}" | ".{}<-" | ".{,}" | ".{,}<-" | ".{,,}" | ".{,,}<-" | ".{,..,}" | ".{,..,}<-" ->
- + let lid' = Longident.( Ldot( Lident "Bigarray" , s ) ) in
- + let r = Env.lookup_value lid' env in
- + Location.prerr_warning loc (Warnings.Deprecated (
- +Printf.sprintf "possible use of ( %s ) as Bigarray.( %s ). To avoid this warning, open the Bigarray module. If you did not intend to use the bigarray index operator, this warning implies that the ( %s ) operator was unbound " s s s ));
- + r
- + | _ -> raise Not_found
- + )
- + | _ -> raise Not_found in
- + try Env.lookup_value lid env with
- + | Not_found -> lookup_deprecated lid env
- +[@@ocaml.deprecated "Temporary hack to ease the introduction of the new index operators .{}/.{,}... "]
- +
- let find_value env loc lid =
- let (path, decl) as r =
- - find_component Env.lookup_value (fun lid -> Unbound_value lid) env loc lid
- - in
- + find_component (lookup_value_with_deprecated_indexop loc) (fun lid -> Unbound_value lid) env loc lid in
- check_deprecated loc decl.val_attributes (Path.name path);
- r
- --
- 2.2.2
Add Comment
Please, Sign In to add comment