[GHC] #14773: MultiWayIf makes it easy to write partial programs that are not catched by -Wall

GHC ghc-devs at haskell.org
Fri Feb 9 00:13:39 UTC 2018


#14773: MultiWayIf makes it easy to write partial programs that are not catched by
-Wall
-------------------------------------+-------------------------------------
        Reporter:  SimonHengel       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      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):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 On second thought, I was too hasty in my earlier assessment—this might be
 more tractable than I thought. It turns out that when we're checking
 patterns from function bindings (as in `program 2` above), we don't
 directly call `checkMatches`, but instead go through an auxiliary function
 called
 [http://git.haskell.org/ghc.git/blob/6edafe3be0133fe69581fb3851a812c69ab9dbf7:/compiler/deSugar/Match.hs#l678
 matchWrapper]. Instead of taking a list of `LPat`s an an argument,
 `matchWrapper` takes a `MatchGroup`, and sets up the necessary scaffolding
 to feed that into `checkMatches`.

 Now, we can't directly feel an `HsMultiIf`'s guards into `matchWrapper`,
 since `HsMultiIf` has an `LGRHS` instead of a `MatchGroup`. However, if we
 look at the definition of `MatchGroup` (and `(L)Match`):

 {{{#!hs
 data MatchGroup p body
   = MG { mg_alts    :: Located [LMatch p body]
        , mg_arg_tys :: [PostTc p Type]
        , mg_res_ty  :: PostTc p Type
        , mg_origin  :: Origin }

 type LMatch id body = Located (Match id body)

 data Match p body
   = Match {
         m_ctxt :: HsMatchContext (NameOrRdrName (IdP p)),
         m_pats :: [LPat p], -- The patterns
         m_grhss :: (GRHSs p body)
   }
 }}}

 We can see that we're actually very close to having what we need, since we
 can slide the `GRHS` right into a `Match`, and put that into the `mg_alts`
 of a `MatchGroup`. The trick is to then come up with suitable things to
 put in the remaining fields of `MatchGroup` and `Match`.

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


More information about the ghc-tickets mailing list