summaryrefslogtreecommitdiff
path: root/docs/users_guide/using-warnings.rst
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-02-23 16:19:34 +0100
committerSebastian Graf <sebastian.graf@kit.edu>2021-03-01 10:49:04 +0100
commite9b1001f66d9e534c58d737d4bedb7ab320d3f92 (patch)
tree9645bc2c78e31c8c30a1998b452fec05ea3605ca /docs/users_guide/using-warnings.rst
parentdb4de0d30193fe56674ccbf7dce0bb35dc325723 (diff)
downloadhaskell-wip/T18610.tar.gz
Pmc: Implement `considerAccessible` (#18610)wip/T18610
Consider (`T18610`): ```hs f :: Bool -> Int f x = case (x, x) of (True, True) -> 1 (False, False) -> 2 (True, False) -> 3 -- Warning: Redundant ``` The third clause will be flagged as redundant. Nevertheless, the programmer might intend to keep the clause in order to avoid bitrot. After this patch, the programmer can write ```hs g :: Bool -> Int g x = case (x, x) of (True, True) -> 1 (False, False) -> 2 (True, False) | GHC.Exts.considerAccessible -> 3 -- No warning ``` And won't be bothered any longer. See also `Note [considerAccessible]` and the updated entries in the user's guide. Fixes #18610 and #19228.
Diffstat (limited to 'docs/users_guide/using-warnings.rst')
-rw-r--r--docs/users_guide/using-warnings.rst28
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst
index a9995268ea..3c09d4c141 100644
--- a/docs/users_guide/using-warnings.rst
+++ b/docs/users_guide/using-warnings.rst
@@ -1235,6 +1235,34 @@ of ``-W(no-)*``.
second pattern overlaps it. More often than not, redundant patterns
is a programmer mistake/error, so this option is enabled by default.
+ If the programmer is dead set of keeping a redundant clause,
+ for example to prevent bitrot, they can make use of a guard
+ scrutinising ``GHC.Exts.considerAccessible`` to prevent the
+ checker from flagging the parent clause as redundant: ::
+
+ g :: String -> Int
+ g [] = 0
+ g (_:xs) = 1
+ g "2" | considerAccessible = 2 -- No warning!
+
+ Note that ``considerAccessible`` should come as the last statement of
+ the guard in order not to impact the results of the checker. E.g., if
+ you write ::
+
+ h :: Bool -> Int
+ h x = case (x, x) of
+ (True, True) -> 1
+ (False, False) -> 2
+ (True, False) | considerAccessible, False <- x -> 3
+
+ The pattern-match checker takes you by your word, will conclude
+ that ``False <- x`` might fail and warn that the pattern-match
+ is inexhaustive. Put ``considerAccessible`` last to avoid such
+ confusions.
+
+ Note that due to technical limitations, ``considerAccessible`` will not
+ suppress :ghc-flag:`-Winaccessible-code` warnings.
+
.. ghc-flag:: -Winaccessible-code
:shortdesc: warn about inaccessible code
:type: dynamic