[GHC] #10746: No non-exhaustive pattern match warning given for empty case analysis
GHC
ghc-devs at haskell.org
Mon Apr 25 22:36:09 UTC 2016
#10746: No non-exhaustive pattern match warning given for empty case analysis
-------------------------------------+-------------------------------------
Reporter: bgamari | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
| PatternMatchWarnings
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #7669, #11806 | Differential Rev(s): Phab:D2105
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
This all seems a bit more complicated than it need be. My guiding light
is that it should all be very similar to `case x of { C y -> blah }`. For
this we enumerate all the data constructors other than `C y` as non-
matching (modulo inaccessible GADT constructors).
We can do the same here. The only real difference is that we don't have a
data constructor `C` to start from. Instead we start from the type of `x
:: tyx`.
So it looks simple:
* Normalise `x`'s type, to get it to the form `T ty1 .. tyn`. (I don't
understand the "bounded" bit.) For this, we must reduce type families,
but NOT newtypes. For pattern matching purposes, newtypes behave just
like data types. So use `FamInstEnv.normaliseType`.
* If `T` has no data constructors, we are done. For example, empty data
types, which don't produce an error message here.
* If none of `T`'s data constructors are GADTs, then just produce an error
of form
{{{
Blah.hs:4:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: _ :: Bool
}}}
Here I've added the "`:: Bool`" part so the reader understands the type
of the pattern. No need to enumerate `True` and `False`.
* If some of `T`'s data constructor are GADTs, then enumerate them all and
recurse.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10746#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list