Skip to content
Snippets Groups Projects
Commit 29086749 authored by Sebastian Graf's avatar Sebastian Graf Committed by Marge Bot
Browse files

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.
parent 4cec6cf2
No related branches found
No related tags found
Loading
Showing
with 186 additions and 125 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment