Opened 11 years ago

Closed 11 years ago

Last modified 4 years ago

#3078 closed bug (duplicate)

Erroneous warnings for -XPatternGuards

Reported by: guest Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

As nonstandard PatternGuards I get a meaningless warning:

walltest.hs:8:10:
    Warning: Pattern match(es) are non-exhaustive
             In the definition of `n': Patterns not matched:
Ok, modules loaded: Main.
{-# LANGUAGE PatternGuards #-}
{-# OPTIONS -Wall #-}

data T = A Int | B Int

funny :: T -> Int
funny t = n
    where n | A x <- t = x
            | B x <- t = x

But none of that happens when using a case expression for the same thing:

{-# OPTIONS -Wall #-}

data T = A Int | B Int

funny :: T -> Int
funny t = n
    where n = case t of
                (A x) -> x
                (B x) -> x

Change History (2)

comment:1 Changed 11 years ago by simonpj

difficulty: Unknown
Resolution: duplicate
Status: newclosed

It's a very special case. For example you might have

... where n | A x <- f t = x
            | B x <- t = x

or

... where n | A x <- t, x>0 = x
            | B x <- t = x

etc. In principle a better exhaustiveness checker could catch some of these cases, and that'd be great. Good suggestion, but it's definitely not simple.

I'm going to close this ticket as a kind-of duplicate, and attach it to the main exhaustiveness checking ticket, namely #595

Simon

comment:2 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
  redundant".

* 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.
Note: See TracTickets for help on using tickets.