Opened 18 years ago

Closed 10 years ago

#29 closed bug (invalid)

Check for exhaustive patterns is broken

Reported by: nobody Owned by:
Priority: lowest Milestone:
Component: Compiler Version: 5.02
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by igloo)

When some of the patterns in a function definition or
case expression contain guards, the compiler gives
false warnings about non-exhaustive pattern matches.  A
pity, because this kind of warning is very useful
indeed!

For example, I get 
 >ghc --make -Wall See.hs
 ghc-5.02.1: chasing modules from: See.hs
 Compiling See              ( See.hs, ./See.o )

 See.hs:17: Warning: Pattern match(es) are
non-exhaustive
     In the definition of `insert':
 	Patterns not matched: _ _ (TREE _ _ _ _)

 See.hs:41: Warning: Pattern match(es) are
non-exhaustive
    In a case alternative EMPTY: Patterns not matched:
TREE _ _ _ _

for the attached file.

[I am not sure filling in the e-mail address box had
any effect on the last two complaints I submitted, so I
repeat my address here:
feliks@crt.se]

Change History (9)

comment:1 Changed 18 years ago by sewardj

Logged In: YES 
user_id=50143


Code is:

insert k v EMPTY = Just (TREE k v EMPTY EMPTY) 


insert k v (TREE k' v' left right) 

| k < k' = case insert k v left of 
Nothing -> Nothing 
Just left' -> Just (TREE k' v' 
left' right) 

| k > k' = case insert k v right of 
Nothing -> Nothing 
Just right' -> Just (TREE k' v' 
left right') 

| k == k' = Nothing 

comment:2 Changed 13 years ago by igloo

Architecture: Unknown
Description: modified (diff)
difficulty: Unknown
Milestone: _|_
Operating System: Unknown

comment:3 Changed 12 years ago by simonmar

See also #1307

comment:4 Changed 12 years ago by simonmar

See #595

comment:5 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:7 Changed 10 years ago by igloo

Owner: nobody deleted
Status: assignednew

comment:8 Changed 10 years ago by ganesh

Type of failure: None/Unknown

This is an unsolvable issue. Consider this simplified example:

foo x | x == 0 = 0
      | x /= 0 = 0

For "correct" Eq implementations these patterns are indeed exhaustive. But (a) GHC has no evidence that all Eq implementations are "correct", and (b) in general it would be undecidable to check whether arbitrary guards are exhaustive or not.

comment:9 Changed 10 years ago by ganesh

Resolution: Noneinvalid
Status: newclosed
Note: See TracTickets for help on using tickets.