···266266- MPR#7864, GPR#2109: remove duplicates from spelling suggestions.
267267 (Nicolás Ojeda Bär, review by Armaël Guéneau)
268268269269+- MPR#6638, GPR#1110: introduced a dedicated warning to report
270270+ unused "open!" statements
271271+ (Alain Frisch, report by dwang, review by and design from Leo White)
272272+273273+269274### Code generation and optimizations:
270275271276- MPR#7725, GPR#1754: improve AFL instrumentation for objects and lazy values.
···627632- GPR#2130: fix printing of type variables with a quote in their name
628633 (Alain Frisch, review by Armaël Guéneau and Gabriel Scherer,
629634 report by Hugo Heuzard)
635635+630636631637OCaml 4.07.1 (4 October 2018)
632638-----------------------------
···97697665
977977\ \ Type declaration defining a new '()' constructor
978978979979+66
980980+\ \ Unused open! statement.
981981+979982The letters stand for the following sets of warnings. Any letter not
980983mentioned here corresponds to the empty set.
981984···1029103210301033.IP
10311034The default setting is
10321032-.BR \-w\ +a\-4\-6\-7\-9\-27\-29\-32..42\-44\-45\-48\-50\-60 .
10351035+.BR \-w\ +a\-4\-6\-7\-9\-27\-29\-32..42\-44\-45\-48\-50\-60\-66 .
10331036Note that warnings
10341037.BR 5 \ and \ 10
10351038are not always triggered, depending on the internals of the type checker.
···1414(* *)
1515(**************************************************************************)
16161717-[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1717+[@@@ocaml.warning "+a-4-9-30-40-41-42-66"]
1818open! Int_replace_polymorphic_compare
19192020(* This cannot be done in a single simple pass due to expressions like:
···1414(* *)
1515(**************************************************************************)
16161717-[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1717+[@@@ocaml.warning "+a-4-9-30-40-41-42-66"]
1818open! Int_replace_polymorphic_compare
19192020(* Simple approximation of the space cost of a primitive. *)
···1414(* *)
1515(**************************************************************************)
16161717-[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1717+[@@@ocaml.warning "+a-4-9-30-40-41-42-66"]
1818open! Int_replace_polymorphic_compare
19192020(* CR-someday mshinwell: Move these three types into their own modules. *)
···1414(* *)
1515(**************************************************************************)
16161717-[@@@ocaml.warning "+a-4-9-30-40-41-42"]
1717+[@@@ocaml.warning "+a-4-9-30-40-41-42-66"]
1818open! Int_replace_polymorphic_compare
19192020(** A variable in a closure can either be used by the closure itself
···11+(* TEST
22+ flags = " -w A-41-42-18"
33+ * expect
44+*)
55+module T1 : sig end = struct
66+ module M = struct type t end (* unused type t *)
77+ open M (* unused open *)
88+end;;
99+[%%expect{|
1010+Line 2, characters 20-26:
1111+2 | module M = struct type t end (* unused type t *)
1212+ ^^^^^^
1313+Warning 34: unused type t.
1414+Line 3, characters 2-8:
1515+3 | open M (* unused open *)
1616+ ^^^^^^
1717+Warning 33: unused open M.
1818+module T1 : sig end
1919+|}]
2020+2121+2222+module T2 : sig type s end = struct
2323+ module M = struct type t end
2424+ open M (* used by line below *)
2525+ type s = t
2626+end;;
2727+[%%expect{|
2828+module T2 : sig type s end
2929+|}]
3030+3131+module T3 : sig end = struct
3232+ type t0 = A (* unused type and constructor *)
3333+ module M = struct type t = A end
3434+ open M (* used by line below; shadow constructor A *)
3535+ let _ = A (* A belongs to several types *)
3636+end;;
3737+[%%expect{|
3838+Line 4, characters 2-8:
3939+4 | open M (* used by line below; shadow constructor A *)
4040+ ^^^^^^
4141+Warning 45: this open statement shadows the constructor A (which is later used)
4242+Line 2, characters 2-13:
4343+2 | type t0 = A (* unused type and constructor *)
4444+ ^^^^^^^^^^^
4545+Warning 34: unused type t0.
4646+Line 2, characters 2-13:
4747+2 | type t0 = A (* unused type and constructor *)
4848+ ^^^^^^^^^^^
4949+Warning 37: unused constructor A.
5050+module T3 : sig end
5151+|}]
5252+5353+module T4 : sig end = struct
5454+ type t0 = A
5555+ module M = struct type t = A end (* unused type and constructor *)
5656+ open M (* unused open; no shadowing (A below refers to the one in t0) *)
5757+ let _ : t0 = A (* disambiguation used *)
5858+end;;
5959+[%%expect{|
6060+Line 3, characters 20-30:
6161+3 | module M = struct type t = A end (* unused type and constructor *)
6262+ ^^^^^^^^^^
6363+Warning 34: unused type t.
6464+Line 3, characters 20-30:
6565+3 | module M = struct type t = A end (* unused type and constructor *)
6666+ ^^^^^^^^^^
6767+Warning 37: unused constructor A.
6868+Line 4, characters 2-8:
6969+4 | open M (* unused open; no shadowing (A below refers to the one in t0) *)
7070+ ^^^^^^
7171+Warning 33: unused open M.
7272+module T4 : sig end
7373+|}]
7474+7575+module T5 : sig end = struct
7676+ type t0 = A (* unused type and constructor *)
7777+ module M = struct type t = A end
7878+ open M (* shadow constructor A *)
7979+ let _ : t = A
8080+end;;
8181+[%%expect{|
8282+Line 4, characters 2-8:
8383+4 | open M (* shadow constructor A *)
8484+ ^^^^^^
8585+Warning 45: this open statement shadows the constructor A (which is later used)
8686+Line 2, characters 2-13:
8787+2 | type t0 = A (* unused type and constructor *)
8888+ ^^^^^^^^^^^
8989+Warning 34: unused type t0.
9090+Line 2, characters 2-13:
9191+2 | type t0 = A (* unused type and constructor *)
9292+ ^^^^^^^^^^^
9393+Warning 37: unused constructor A.
9494+module T5 : sig end
9595+|}]
9696+9797+9898+module T1_bis : sig end = struct
9999+ module M = struct type t end (* unused type t *)
100100+ open! M (* unused open *)
101101+end;;
102102+[%%expect{|
103103+Line 2, characters 20-26:
104104+2 | module M = struct type t end (* unused type t *)
105105+ ^^^^^^
106106+Warning 34: unused type t.
107107+Line 3, characters 2-9:
108108+3 | open! M (* unused open *)
109109+ ^^^^^^^
110110+Warning 66: unused open! M.
111111+module T1_bis : sig end
112112+|}]
113113+114114+module T2_bis : sig type s end = struct
115115+ module M = struct type t end
116116+ open! M (* used by line below *)
117117+ type s = t
118118+end;;
119119+[%%expect{|
120120+module T2_bis : sig type s end
121121+|}]
122122+123123+module T3_bis : sig end = struct
124124+ type t0 = A (* unused type and constructor *)
125125+ module M = struct type t = A end
126126+ open! M (* used by line below; shadow constructor A (disabled) *)
127127+ let _ = A (* A belongs to several types *)
128128+end;;
129129+[%%expect{|
130130+Line 2, characters 2-13:
131131+2 | type t0 = A (* unused type and constructor *)
132132+ ^^^^^^^^^^^
133133+Warning 34: unused type t0.
134134+Line 2, characters 2-13:
135135+2 | type t0 = A (* unused type and constructor *)
136136+ ^^^^^^^^^^^
137137+Warning 37: unused constructor A.
138138+module T3_bis : sig end
139139+|}]
140140+141141+module T4_bis : sig end = struct
142142+ type t0 = A
143143+ module M = struct type t = A end (* unused type and constructor *)
144144+ open! M (* unused open; no shadowing (A below refers to the one in t0) *)
145145+ let _ : t0 = A (* disambiguation used *)
146146+end;;
147147+[%%expect{|
148148+Line 3, characters 20-30:
149149+3 | module M = struct type t = A end (* unused type and constructor *)
150150+ ^^^^^^^^^^
151151+Warning 34: unused type t.
152152+Line 3, characters 20-30:
153153+3 | module M = struct type t = A end (* unused type and constructor *)
154154+ ^^^^^^^^^^
155155+Warning 37: unused constructor A.
156156+Line 4, characters 2-9:
157157+4 | open! M (* unused open; no shadowing (A below refers to the one in t0) *)
158158+ ^^^^^^^
159159+Warning 66: unused open! M.
160160+module T4_bis : sig end
161161+|}]
162162+163163+module T5_bis : sig end = struct
164164+ type t0 = A (* unused type and constructor *)
165165+ module M = struct type t = A end
166166+ open! M (* shadow constructor A (disabled) *)
167167+ let _ : t = A
168168+end;;
169169+[%%expect{|
170170+Line 2, characters 2-13:
171171+2 | type t0 = A (* unused type and constructor *)
172172+ ^^^^^^^^^^^
173173+Warning 34: unused type t0.
174174+Line 2, characters 2-13:
175175+2 | type t0 = A (* unused type and constructor *)
176176+ ^^^^^^^^^^^
177177+Warning 37: unused constructor A.
178178+module T5_bis : sig end
179179+|}]
+4
testsuite/tests/warnings/w33.compilers.reference
···2219 | let f M.(x) = x (* useless open *)
33 ^^^^^
44Warning 33: unused open M.
55+File "w33.ml", line 26, characters 0-7:
66+26 | open! M (* useless open! *)
77+ ^^^^^^^
88+Warning 66: unused open! M.
59File "w33.ml", line 27, characters 0-6:
61027 | open M (* useless open *)
711 ^^^^^^
+1-1
testsuite/tests/warnings/w33.ml
···2323open N (* used open *)
2424let i (A|B) = B
25252626-open! M (* open! also deactivates unused open warning *)
2626+open! M (* useless open! *)
2727open M (* useless open *)
+24-12
typing/env.ml
···21572157 ?(used_slot = ref false)
21582158 ?(loc = Location.none) ?(toplevel = false)
21592159 ovf root env =
21602160- if not toplevel && ovf = Asttypes.Fresh && not loc.Location.loc_ghost
21612161- && (Warnings.is_active (Warnings.Unused_open "")
21622162- || Warnings.is_active (Warnings.Open_shadow_identifier ("", ""))
21632163- || Warnings.is_active (Warnings.Open_shadow_label_constructor ("","")))
21602160+ let unused =
21612161+ match ovf with
21622162+ | Asttypes.Fresh -> Warnings.Unused_open (Path.name root)
21632163+ | Asttypes.Override -> Warnings.Unused_open_bang (Path.name root)
21642164+ in
21652165+ let warn_unused =
21662166+ Warnings.is_active unused
21672167+ and warn_shadow_id =
21682168+ Warnings.is_active (Warnings.Open_shadow_identifier ("", ""))
21692169+ and warn_shadow_lc =
21702170+ Warnings.is_active (Warnings.Open_shadow_label_constructor ("",""))
21712171+ in
21722172+ if not toplevel && not loc.Location.loc_ghost
21732173+ && (warn_unused || warn_shadow_id || warn_shadow_lc)
21642174 then begin
21652175 let used = used_slot in
21662166- !add_delayed_check_forward
21672167- (fun () ->
21682168- if not !used then begin
21692169- used := true;
21702170- Location.prerr_warning loc (Warnings.Unused_open (Path.name root))
21712171- end
21722172- );
21762176+ if warn_unused then
21772177+ !add_delayed_check_forward
21782178+ (fun () ->
21792179+ if not !used then begin
21802180+ used := true;
21812181+ Location.prerr_warning loc unused
21822182+ end
21832183+ );
21732184 let shadowed = ref [] in
21742185 let slot s b =
21752186 begin match check_shadowing env b with
21762176- | Some kind when not (List.mem (kind, s) !shadowed) ->
21872187+ | Some kind when
21882188+ ovf = Asttypes.Fresh && not (List.mem (kind, s) !shadowed) ->
21772189 shadowed := (kind, s) :: !shadowed;
21782190 let w =
21792191 match kind with
+6-2
utils/warnings.ml
···9090 | Erroneous_printed_signature of string (* 63 *)
9191 | Unsafe_without_parsing (* 64 *)
9292 | Redefining_unit of string (* 65 *)
9393+ | Unused_open_bang of string (* 66 *)
9394;;
94959596(* If you remove a warning, leave a hole in the numbering. NEVER change
···164165 | Erroneous_printed_signature _ -> 63
165166 | Unsafe_without_parsing -> 64
166167 | Redefining_unit _ -> 65
168168+ | Unused_open_bang _ -> 66
167169;;
168170169169-let last_warning_number = 65
171171+let last_warning_number = 66
170172;;
171173172174(* Must be the max number returned by the [number] function. *)
···301303 current := {error; active}
302304303305(* If you change these, don't forget to change them in man/ocamlc.m *)
304304-let defaults_w = "+a-4-6-7-9-27-29-32..42-44-45-48-50-60";;
306306+let defaults_w = "+a-4-6-7-9-27-29-32..42-44-45-48-50-60-66";;
305307let defaults_warn_error = "-a+31";;
306308307309let () = parse_options false defaults_w;;
···401403 file1 file2 modname
402404 | Unused_value_declaration v -> "unused value " ^ v ^ "."
403405 | Unused_open s -> "unused open " ^ s ^ "."
406406+ | Unused_open_bang s -> "unused open! " ^ s ^ "."
404407 | Unused_type_declaration s -> "unused type " ^ s ^ "."
405408 | Unused_for_index s -> "unused for-loop index " ^ s ^ "."
406409 | Unused_ancestor s -> "unused ancestor variable " ^ s ^ "."
···661664 63, "Erroneous printed signature";
662665 64, "-unsafe used with a preprocessor returning a syntax tree";
663666 65, "Type declaration defining a new '()' constructor";
667667+ 66, "Unused open! statement";
664668 ]
665669;;
666670