[GHC] #14547: Wrong warning by -Wincomplete-patterns

GHC ghc-devs at haskell.org
Wed Apr 25 08:19:52 UTC 2018


#14547: Wrong warning by -Wincomplete-patterns
-------------------------------------+-------------------------------------
        Reporter:  YoshikuniJujo     |                Owner:  (none)
            Type:  bug               |               Status:  patch
        Priority:  low               |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:                    |             Keywords:  incomplete-
                                     |  patterns OverloadedLists,
                                     |  PatternMatchWarnings TypeFamilies
Operating System:  Linux             |         Architecture:  x86
 Type of failure:  Incorrect         |            Test Case:
  error/warning at compile-time      |  deSugar/should_compile/T14547
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4624
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by sighingnow):

 My previous comment addresses on `toList`, leading to some confusion. The
 ticket **IS** about the type functions.

 Look the `ListPat` case in `translatePat` (after the patch Phab:D4624):

 {{{#!hs
   -- overloaded list
   ListPat x lpats elem_ty (Just (pat_ty, _to_list))
     | Just e_ty <- splitListTyConApp_maybe pat_ty
     , (_, norm_e_ty) <- normaliseType fam_insts Nominal e_ty
          -- e_ty can be a type family instance, like
          -- `It (List a)`, but we prefer `a`, see Trac #14547
     , (_, norm_elem_ty) <- normaliseType fam_insts Nominal elem_ty
          -- elem_ty is frequently something like
          -- `Item [Int]`, but we prefer `Int`
     , norm_elem_ty `eqType` norm_e_ty ->
         -- We have to ensure that the element types are exactly the same.
         -- Otherwise, one may give an instance IsList [Int] (more specific
 than
         -- the default IsList [a]) with a different implementation for
 `toList'

         translatePat fam_insts (ListPat x lpats e_ty Nothing)
       -- See Note [Guards and Approximation]
     | otherwise -> mkCanFailPmPat pat_ty
 }}}

 For pattern `[]` in `foo [] = Empty`, we have

 ||pat_ty        || `[It (List a_a2mv)]`      ||
 ||e_ty          || `It (List a_a2mv)`         ||
 ||norm_e_ty     || `a_a2mv`                    ||
 ||elem_ty       || `GHC.Exts.Item [a_a2mv]` ||
 ||norm_elem_ty || `a_a2mv`                    ||

 Before Phab:4624, we compared `norm_elem_ty` with `e_ty`, rather than
 `norm_e_ty`, then we failed to know the `[]` is list's nil pattern. We
 need also normalize the `e_ty` and this ticket is only about the type
 function.

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


More information about the ghc-tickets mailing list