Opened 6 years ago

Closed 4 years ago

Last modified 19 months ago

#8970 closed bug (duplicate)

Non-exhaustive pattern match warning with DataKinds and TypeFamilies

Reported by: tensor5 Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.3
Keywords: PatternMatchWarnings Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: #3927 #6124 Differential Rev(s):
Wiki Page:


The code is:

data K = Foo
       | Bar

data D1 :: K -> * where
    F1 :: D1 Foo
    B1 :: D1 Bar

class C (a :: K -> *) where
    data D2 a :: K -> *
    foo :: a k -> D2 a k -> Bool

instance C D1 where
    data D2 D1 k where
              F2 :: D2 D1 Foo
              B2 :: D2 D1 Bar
    foo F1 F2 = True
    foo B1 B2 = True

With -Wall it gives the warning:

Test.hs:23:5: Warning:
    Pattern match(es) are non-exhaustive
    In an equation for `foo':
        Patterns not matched:
            F1 B2
            B1 F2

Attachments (1)

Test.hs (543 bytes) - added by tensor5 6 years ago.

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by tensor5

Attachment: Test.hs added

comment:1 Changed 6 years ago by tensor5

Type of failure: None/UnknownIncorrect warning at compile-time

comment:2 Changed 6 years ago by simonpj

Yes, I think this is a long-outstanding bug, awaiting someone with some time and attention. See #6124 for example.


comment:3 Changed 6 years ago by jstolarek

comment:4 Changed 4 years ago by thomie

Resolution: duplicate
Status: newclosed

Because the existence of duplicate tickets makes doing a BugSweep of the bug tracker more cumbersome, I'm closing these tickets as duplicate. Don't worry, they're still listed on PatternMatchCheck, and will hopefully all be addressed by the work on #595 ("Overhaul GHC's overlapping/non-exhaustive pattern checking").

comment:5 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:6 Changed 19 months ago by simonpj

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