[GHC] #13964: Pattern-match warnings for datatypes with COMPLETE sets break abstraction

GHC ghc-devs at haskell.org
Wed Jul 12 19:18:41 UTC 2017


#13964: Pattern-match warnings for datatypes with COMPLETE sets break abstraction
-------------------------------------+-------------------------------------
           Reporter:  RyanGlScott    |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
  PatternSynonyms,                   |
  PatternMatchWarnings               |
       Architecture:                 |   Type of failure:  Poor/confusing
  Unknown/Multiple                   |  error message
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Here's a file:

 {{{#!hs
 {-# LANGUAGE PatternSynonyms #-}
 {-# LANGUAGE ViewPatterns #-}
 module Bug (Boolean(F, TooGoodToBeTrue), catchAll) where

 data Boolean = F | T
   deriving Eq

 pattern TooGoodToBeTrue :: Boolean
 pattern TooGoodToBeTrue <- ((== T) -> True)
   where
     TooGoodToBeTrue = T
 {-# COMPLETE F, TooGoodToBeTrue #-}

 catchAll :: Boolean -> Int
 catchAll F               = 0
 -- catchAll TooGoodToBeTrue = 1
 }}}

 If you compile this with `-Wall`, the warning will warn about `T`, not
 `TooGoodToBeTrue` (the other conlike in the `COMPLETE` set):

 {{{
 $ /opt/ghc/8.2.1/bin/ghc -fforce-recomp -Wall Bug.hs
 [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

 Bug.hs:15:1: warning: [-Wincomplete-patterns]
     Pattern match(es) are non-exhaustive
     In an equation for ‘catchAll’: Patterns not matched: T
    |
 15 | catchAll F               = 0
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }}}

 Perhaps this isn't so bad, since it's intra-module. But the problem
 persists even across modules:

 {{{#!hs
 module Foo where

 import Bug

 catchAll2 :: Boolean -> Int
 catchAll2 F               = 0
 -- catchAll2 TooGoodToBeTrue = 1
 }}}

 {{{
 $ /opt/ghc/8.2.1/bin/ghc -fforce-recomp -c Bug.hs
 $ /opt/ghc/8.2.1/bin/ghc -fforce-recomp -c -Wall Foo.hs

 Foo.hs:6:1: warning: [-Wincomplete-patterns]
     Pattern match(es) are non-exhaustive
     In an equation for ‘catchAll2’: Patterns not matched: Bug.T
   |
 6 | catchAll2 F               = 0
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }}}

 This one is really bad, since it's warning about `Bug.T`, which should be
 hidden!

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


More information about the ghc-tickets mailing list