Skip to content

Commit

Permalink
Make warning always fire, fatal in 3.4
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Jul 20, 2022
1 parent b1068bc commit 10087d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
20 changes: 10 additions & 10 deletions src/dune_rules/dune_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,18 @@ module Stanza = struct
(pat, configs))

let check_rules ~version ~loc rules =
let has_after_any l =
let is_any = function
| Any, _ -> true
| Profile _, _ -> false
in
List.split_while l ~f:is_any |> snd |> List.is_non_empty
let rec has_after_any = function
| [ (Any, _) ] -> false
| (Any, _) :: _ :: _ -> true
| (Profile _, _) :: rules -> has_after_any rules
| [] -> false
in
if version >= (3, 4) && has_after_any rules then
User_warning.emit ~loc
if has_after_any rules then
let is_error = version >= (3, 4) in
User_warning.emit ~loc ~is_error
[ Pp.text
"This stanza contains rules after a wildcard rule. These are going \
to be ignored."
"This env stanza contains rules after a wildcard rule. These are \
going to be ignored."
]

let decode =
Expand Down
15 changes: 12 additions & 3 deletions test/blackbox-tests/test-cases/env/env-unused.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
> (dev (env-vars (VAR specific))))
> EOF

A warning is displayed when there are unreachable cases.

$ dune runtest
File "dune", line 5, characters 0-71:
5 | (env
6 | (_ (env-vars (VAR default )))
7 | (dev (env-vars (VAR specific))))
Warning: This env stanza contains rules after a wildcard rule. These are
going to be ignored.
default

In 3.4, a warning is added for that case:
In 3.4, this warning becomes fatal.

$ cat > dune-project << EOF
> (lang dune 3.4)
Expand All @@ -28,5 +36,6 @@ In 3.4, a warning is added for that case:
5 | (env
6 | (_ (env-vars (VAR default )))
7 | (dev (env-vars (VAR specific))))
Warning: This stanza contains rules after a wildcard rule. These are going to
be ignored.
Error: This env stanza contains rules after a wildcard rule. These are going
to be ignored.
[1]

0 comments on commit 10087d7

Please sign in to comment.