Ticket #29 (closed bug: invalid)

Opened 11 years ago

Last modified 3 years ago

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 Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

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

Changed 10 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 

Changed 6 years ago by igloo

  • difficulty set to Unknown
  • milestone set to _|_
  • os set to Unknown
  • architecture set to Unknown
  • description modified (diff)

Changed 5 years ago by simonmar

See also #1307

Changed 5 years ago by simonmar

See #595

Changed 4 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 4 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 3 years ago by igloo

  • owner nobody deleted
  • status changed from assigned to new

Changed 3 years ago by ganesh

  • failure set to 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.

Changed 3 years ago by ganesh

  • status changed from new to closed
  • resolution changed from None to invalid
Note: See TracTickets for help on using tickets.