#5813: Offer a compiler warning for failable pattern matches
------------------------------+---------------------------------------------
 Reporter:  snoyberg          |          Owner:                  
     Type:  bug               |         Status:  new             
 Priority:  normal            |      Component:  Compiler        
  Version:  7.2.2             |       Keywords:                  
       Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown      |       Testcase:                  
Blockedby:                    |       Blocking:                  
  Related:                    |  
------------------------------+---------------------------------------------
 This started off with a mailing list discussion: [http://www.mail-
 archive.com/haskell-c...@haskell.org/msg96517.html]. The problem is that
 the following code produces no compile-time warning and results in a
 runtime error:


 {{{
 data MyType = Foo | Bar
     deriving Show

 test :: Monad m => m MyType -> m ()
 test myType = do
     Foo <- myType
     return ()

 main :: IO ()
 main = test $ return Bar
 }}}

 This is in contrast to the rest of pattern matching, which would warn
 about unmatched patterns, e.g.:

 {{{
 data MyType = Foo | Bar
     deriving Show

 test :: Monad m => m MyType -> m ()
 test myType = do
     x <- myType
     case x of
         Foo -> return ()

 main :: IO ()
 main = test $ return Bar
 }}}

 I understand that this style of code may be very useful in some
 circumstances when paired with a Monad providing a sensible fail
 implementation, and is especially used in list comprehensions. However,
 this is allowing an easily catchable static error to slip through our
 fingers.

 I recommend we add a new compiler warning to catch incomplete patterns in
 do-notation binding. I believe this warning should not apply to list
 comprehensions. Ideally, this warning would be turned on by -Wall.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5813>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to