diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2021-11-10 12:54:59 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-17 05:11:38 -0500 |
commit | 29086749b8d6bec162414fbec8921df0382d0627 (patch) | |
tree | b21134cf637ad64032dc41f3578dc1ba3c783086 /testsuite/tests/th | |
parent | 4cec6cf284d65449bbdaf015fadd7768770ec52b (diff) | |
download | haskell-29086749b8d6bec162414fbec8921df0382d0627.tar.gz |
Pmc: Don't case split on wildcard matches (#20642)
Since 8.10, when formatting a pattern match warning, we'd case split on a
wildcard match such as
```hs
foo :: [a] -> [a]
foo [] = []
foo xs = ys
where
(_, ys@(_:_)) = splitAt 0 xs
-- Pattern match(es) are non-exhaustive
-- In a pattern binding:
-- Patterns not matched:
-- ([], [])
-- ((_:_), [])
```
But that's quite verbose and distracts from which part of the pattern was
actually the inexhaustive one. We'd prefer a wildcard for the first pair
component here, like it used to be in GHC 8.8.
On the other hand, case splitting is pretty handy for `-XEmptyCase` to know the
different constructors we could've matched on:
```hs
f :: Bool -> ()
f x = case x of {}
-- Pattern match(es) are non-exhaustive
-- In a pattern binding:
-- Patterns not matched:
-- False
-- True
```
The solution is to communicate that we want a top-level case split to
`generateInhabitingPatterns` for `-XEmptyCase`, which is exactly what
this patch arranges. Details in `Note [Case split inhabiting patterns]`.
Fixes #20642.
Diffstat (limited to 'testsuite/tests/th')
-rw-r--r-- | testsuite/tests/th/T19709c.stderr | 4 | ||||
-rw-r--r-- | testsuite/tests/th/T19709d.stderr | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/testsuite/tests/th/T19709c.stderr b/testsuite/tests/th/T19709c.stderr index 3bedc08dc9..37451d2023 100644 --- a/testsuite/tests/th/T19709c.stderr +++ b/testsuite/tests/th/T19709c.stderr @@ -4,7 +4,7 @@ T19709c.hs:9:7: error: [-Wincomplete-patterns (in -Wextra), -Werror=incomplete-p In a case alternative: Patterns of type ‘String’ not matched: [] - [p] where p is not one of {'h'} - (p:_:_) where p is not one of {'h'} + (p:_) where p is not one of {'h'} ['h'] + ('h':p:_) where p is not one of {'e'} ... diff --git a/testsuite/tests/th/T19709d.stderr b/testsuite/tests/th/T19709d.stderr index 3ee2ac8424..cacf6acb48 100644 --- a/testsuite/tests/th/T19709d.stderr +++ b/testsuite/tests/th/T19709d.stderr @@ -4,9 +4,9 @@ T19709d.hs:6:2: warning: [-Wincomplete-patterns (in -Wextra)] In a case alternative: Patterns of type ‘String’ not matched: [] - [p] where p is not one of {'h'} - (p:_:_) where p is not one of {'h'} + (p:_) where p is not one of {'h'} ['h'] + ('h':p:_) where p is not one of {'e'} ... T19709d.hs:1:1: error: |