Skip to content

Commit

Permalink
Remove warning 30 from the standard set. (#9568)
Browse files Browse the repository at this point in the history
Warning 30 (same constructor/label name used in two mutually-recursive
declarations) is an annoying warning that makes no sense since we
introduced type-based disambiguation of fields and constructors. It
was disabled by default in OCaml 4.10

  ocaml/ocaml#9046

and there is no reason to keep it in Dune.

Signed-off-by: Gabriel Scherer <gabriel.scherer@gmail.com>
  • Loading branch information
gasche committed Jan 8, 2024
1 parent cd27c29 commit 4f274af
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/changes/9568.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Remove warning 30 from default set for projects where dune lang is at least
3.13 (#9568, @gasche)
20 changes: 17 additions & 3 deletions src/dune_rules/ocaml_flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ let dev_mode_warnings =
(Int.Set.of_list
[ 4; 29; 40; 41; 42; 44; 45; 48; 58; 59; 60; 63; 64; 65; 66; 67; 68; 69; 70 ])
in
let add n range = Int.Set.add range n in
let remove n range = Int.Set.remove range n in
let warnings_range ws =
let wrange_to_flag (x, y) =
if x = y then sprintf "@%d" x else sprintf "@%d..%d" x y
Expand All @@ -25,10 +27,22 @@ let dev_mode_warnings =
|> List.rev_map ~f:wrange_to_flag
|> String.concat ~sep:""
in
let pre_3_3 = lazy (warnings_range all) in
let post_3_3 = lazy (warnings_range (Int.Set.union all (Int.Set.of_list [ 67; 69 ]))) in
let and_warnings lazy_range =
lazy_range, lazy (warnings_range (Lazy.force lazy_range))
in
let range_pre_3_3, pre_3_3 = and_warnings @@ lazy all in
let range_pre_3_13, pre_3_13 =
and_warnings @@ lazy (Lazy.force range_pre_3_3 |> add 67 |> add 69)
in
let _range_later, later =
and_warnings @@ lazy (Lazy.force range_pre_3_13 |> remove 30)
in
fun ~dune_version ->
if dune_version >= (3, 3) then Lazy.force post_3_3 else Lazy.force pre_3_3
if dune_version < (3, 3)
then Lazy.force pre_3_3
else if dune_version < (3, 13)
then Lazy.force pre_3_13
else Lazy.force later
;;

let vendored_warnings = [ "-w"; "-a" ]
Expand Down
25 changes: 25 additions & 0 deletions test/blackbox-tests/test-cases/default-ocaml-flags-3-13.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$ cat >dune <<EOF
> (library
> (modes byte)
> (name foo))
> EOF
$ cat >foo.ml <<EOF
> type a = { a : int }
> and b = { a : int ; b : bool }
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.12)
> EOF
$ dune build foo.cma
File "foo.ml", line 2, characters 10-19:
2 | and b = { a : int ; b : bool }
^^^^^^^^^
Error (warning 30 [duplicate-definitions]): the label a is defined in both types a and b.
[1]
$ cat >dune-project <<EOF
> (lang dune 3.13)
> EOF
$ dune build foo.cma

0 comments on commit 4f274af

Please sign in to comment.