Guest User

Untitled

a guest
Feb 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. From 305524932db142351d1ed4a9520eb29a5f24fa7f Mon Sep 17 00:00:00 2001
  2. From: Octachron <octa@polychoron.fr>
  3. Date: Fri, 30 Jan 2015 17:50:21 +0200
  4. Subject: [PATCH] Warnings for using .{} without opening Bigarray
  5.  
  6. The previous change to the index operator .{} (and friends) broke backward
  7. source code compatibility with the previous version of Ocaml. Program using
  8. these operators without opening the Bigarray module triggered an error.
  9. To alleviate this problem, this patch adds a temporary hack to the type
  10. checker to transform the corresponding errors in a warning.
  11. ---
  12. typing/typetexp.ml | 23 +++++++++++++++++++++--
  13. 1 file changed, 21 insertions(+), 2 deletions(-)
  14.  
  15. diff --git a/typing/typetexp.ml b/typing/typetexp.ml
  16. index 523d435..e7b99bc 100644
  17. --- a/typing/typetexp.ml
  18. +++ b/typing/typetexp.ml
  19. @@ -239,10 +239,29 @@ let find_class env loc lid =
  20. check_deprecated loc decl.cty_attributes (Path.name path);
  21. r
  22.  
  23. +(* With the simplification of index operators, the expression a.{..} are no longer resolved to Bigarray.Array[n].[g|s]et.
  24. +To ease the transition period, we catch the case where the index operators .{}/.{,}.. are not bound in the current scope and reintroduce the
  25. +binding with a deprecation warning. *)
  26. +let lookup_value_with_deprecated_indexop loc lid env =
  27. +let lookup_deprecated lid env =
  28. + match lid with
  29. + | Longident.Lident s -> ( match s with
  30. + | ".{}" | ".{}<-" | ".{,}" | ".{,}<-" | ".{,,}" | ".{,,}<-" | ".{,..,}" | ".{,..,}<-" ->
  31. + let lid' = Longident.( Ldot( Lident "Bigarray" , s ) ) in
  32. + let r = Env.lookup_value lid' env in
  33. + Location.prerr_warning loc (Warnings.Deprecated (
  34. +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 ));
  35. + r
  36. + | _ -> raise Not_found
  37. + )
  38. + | _ -> raise Not_found in
  39. + try Env.lookup_value lid env with
  40. + | Not_found -> lookup_deprecated lid env
  41. +[@@ocaml.deprecated "Temporary hack to ease the introduction of the new index operators .{}/.{,}... "]
  42. +
  43. let find_value env loc lid =
  44. let (path, decl) as r =
  45. - find_component Env.lookup_value (fun lid -> Unbound_value lid) env loc lid
  46. - in
  47. + find_component (lookup_value_with_deprecated_indexop loc) (fun lid -> Unbound_value lid) env loc lid in
  48. check_deprecated loc decl.val_attributes (Path.name path);
  49. r
  50.  
  51. --
  52. 2.2.2
Add Comment
Please, Sign In to add comment