Opened 8 years ago

Closed 6 years ago

Last modified 19 months ago

#5724 closed bug (duplicate)

Confusing warning message for incomplete patterns

Reported by: AntoineLatter Owned by:
Priority: normal Milestone: 7.6.2
Component: Compiler Version: 7.3
Keywords: PatternMatchWarnings Cc: leroux@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following code

{-# OPTIONS_GHC -Wall #-}

import Data.Word

f :: Word8 -> Bool
f 0 = True
f 1 = False
f 2 = True

Produces the warning

    Warning: Pattern match(es) are non-exhaustive
             In an equation for `f':
                 Patterns not matched: #x with #x `notElem` [0#, 1#, 2#]

While accurate, this is not exactly user friendly.

Found in GHC 7.4.1 RC 1

Change History (7)

comment:1 Changed 8 years ago by AntoineLatter

Strings are also weird. We show the error for primitive chars, which is one problem. Bonus points for adding a special case for lists of chars.

g :: String -> Bool
g "Hello" = True
g "World" = False
    Warning: Pattern match(es) are non-exhaustive
             In an equation for `g':
                 Patterns not matched:
                     (GHC.Types.C# #x) : _ with #x `notElem` ['H', 'W']
                     [GHC.Types.C# 'H']
                     (GHC.Types.C# 'H') : ((GHC.Types.C# #x) : _)
                     #x `notElem` ['e']

comment:2 Changed 8 years ago by igloo

difficulty: Unknown
Milestone: 7.6.1

Can you please say exactly what you would like the warning to look like?

comment:3 Changed 7 years ago by igloo


comment:4 Changed 6 years ago by leroux

Cc: leroux@… added
Status: newinfoneeded

As igloo asked 20 months ago, did you have an alternative message in mind?

comment:5 Changed 6 years ago by monoidal

Resolution: duplicate
Status: infoneededclosed

Closing as duplicate of #2204.

comment:6 Changed 4 years ago by George Karachalias <george.karachalias@…>

In 8a506104/ghc:

Major Overhaul of Pattern Match Checking (Fixes #595)

This patch adresses several problems concerned with exhaustiveness and
redundancy checking of pattern matching. The list of improvements includes:

* Making the check type-aware (handles GADTs, Type Families, DataKinds, etc.).
  This fixes #4139, #3927, #8970 and other related tickets.

* Making the check laziness-aware. Cases that are overlapped but affect
  evaluation are issued now with "Patterns have inaccessible right hand side".
  Additionally, "Patterns are overlapped" is now replaced by "Patterns are

* Improved messages for literals. This addresses tickets #5724, #2204, etc.

* Improved reasoning concerning cases where simple and overloaded
  patterns are matched (See #322).

* Substantially improved reasoning for pattern guards. Addresses #3078.

* OverloadedLists extension does not break exhaustiveness checking anymore
  (addresses #9951). Note that in general this cannot be handled but if we know
  that an argument has type '[a]', we treat it as a list since, the instance of
  'IsList' gives the identity for both 'fromList' and 'toList'. If the type is
  not clear or is not the list type, then the check cannot do much still. I am
  a bit concerned about OverlappingInstances though, since one may override the
  '[a]' instance with e.g. an '[Int]' instance that is not the identity.

* Improved reasoning for nested pattern matching (partial solution). Now we
  propagate type and (some) term constraints deeper when checking, so we can
  detect more inconsistencies. For example, this is needed for #4139.

I am still not satisfied with several things but I would like to address at
least the following before the next release:
    Term constraints are too many and not printed for non-exhaustive matches
(with the exception of literals). This sometimes results in two identical (in
appearance) uncovered warnings. Unless we actually show their difference, I
would like to have a single warning.

comment:7 Changed 19 months ago by simonpj

Keywords: PatternMatchWarnings added
Note: See TracTickets for help on using tickets.