[GHC] #15385: -Wincomplete-patterns gets confused when combining GADTs and pattern guards

GHC ghc-devs at haskell.org
Wed Jul 25 16:45:42 UTC 2018


#15385: -Wincomplete-patterns gets confused when combining GADTs and pattern guards
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  patch
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.5
      Resolution:                    |             Keywords:
                                     |  PatternMatchWarnings
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4968
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Gah.  The deeper I dig the less happy I am.  The `addDictsDs` is ok, but
 I'm worried
 about `genCaseTmCs1` and `genCaseTmCs2`

 The basic idea here is that when we see (in source Haskell)
 {{{
    case x of { (a, Just b) -> blah }
 }}}
 we want to desugar `blah` in the knowledge that
 {{{
    x ~ (a, Just b)
 }}}
 Reason: suppose that somewhere inside `blah` we see
 {{{
      case x of { (a, Nothing) -> blah2 }
 }}}
 Then we want to declare this branch as unreachable.

 But what if the original expression was
 {{{
    case x of (a, Just _) -> blah
 }}}
 Now what equality do we generate?  Maybe we make a fresh variable?
 And maybe that is waht we want.  This conversion from a pattern to
 a `PmExpr` is all hidden inside the cryptic line
 {{{
   [e] <- map vaToPmExpr . coercePatVec <$> translatePat fam_insts p
 }}}
 I have very little idea of what this does.

 Returning to our case expression, we'll end up using `genCaseTmCs2`
 in `matchWrapper`.  And that seems to generate ''two'' equalities
 {{{
   v ~ (a, Just b)
   v ~ x
 }}}
 That seems terribly indirect, although perhaps not actually wrong.
 I suppose that it might work in cases like
 {{{
    case (p,q) of (a, Just b) -> blah
 }}}
 but they probably never happen -- and at very least it could do with
 explanation.

 Bottom line so far: no actual bugs, but pretty tough going.

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


More information about the ghc-tickets mailing list