Opened 6 years ago

Closed 2 years ago

#5762 closed bug (duplicate)

GHC gives incorrect warnings with simple applications of the view patterns extension

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

Description

GHC is not able to infer exhaustivity of f1 in the following example

{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
module VP where


f1, f2 :: Either Int Int -> Either Int Int

f1 (id -> Left _ ) = undefined
f1 (id -> Right _ ) = undefined

f2 (Left _ ) = undefined
f2 (Right _ ) = undefined


f (id -> _) = undefined

GHC outputs:

[1 of 1] Compiling VP               ( VP.hs, interpreted )

VP.hs:8:1:
    Warning: Pattern match(es) are non-exhaustive
             In an equation for `f1': Patterns not matched: _
Ok, modules loaded: VP.

I've tested this with GHC 7.0.4, 7.2.2, and 7.4.1-rc1 on Mac OS X.

BTW: There is neither a version entry for 7.2.2 nor for 7.4.1-rc1 in Trac.

Change History (3)

comment:1 Changed 6 years ago by simonpj

difficulty: Unknown
Milestone: _|_

Not easy to solve this; cf #595, #5728, #3927, #5724. Volunteers welcome.

comment:2 Changed 4 years ago by hvr

PatternGuards can result in a similar spurious warning, i.e.

module Foo where

foo :: Either t t -> t
foo x | Left  l <- x = l
      | Right r <- x = r

bar :: Either t t -> t
bar x = v
  where
    v | Left l <- x = l
      | Right r <- x = r

leads to

Foo.hs:4:1: Warning:
    Pattern match(es) are non-exhaustive
    In an equation for `foo': Patterns not matched: _

Foo.hs:10:5: Warning:
    Pattern match(es) are non-exhaustive
    In an equation for `v': Patterns not matched:

comment:3 Changed 2 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").

Note: See TracTickets for help on using tickets.