From 10087d701236277626d7d037e21420d38f50ad7a Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Mon, 27 Jun 2022 09:50:27 +0200 Subject: [PATCH] Make warning always fire, fatal in 3.4 Signed-off-by: Etienne Millon --- src/dune_rules/dune_env.ml | 20 +++++++++---------- .../test-cases/env/env-unused.t | 15 +++++++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/dune_rules/dune_env.ml b/src/dune_rules/dune_env.ml index 806c3b47d40a..065fa7799601 100644 --- a/src/dune_rules/dune_env.ml +++ b/src/dune_rules/dune_env.ml @@ -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 = diff --git a/test/blackbox-tests/test-cases/env/env-unused.t b/test/blackbox-tests/test-cases/env/env-unused.t index ef722d710c39..de818b175370 100644 --- a/test/blackbox-tests/test-cases/env/env-unused.t +++ b/test/blackbox-tests/test-cases/env/env-unused.t @@ -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) @@ -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]