[GHC] #11475: Lint should check for inexhaustive alternatives

GHC ghc-devs at haskell.org
Sat Feb 27 12:39:35 UTC 2016


#11475: Lint should check for inexhaustive alternatives
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             Keywords:
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 jscholl):

 Using the {{{CRPResult}}} did indeed help, I can now compile a few more
 modules. However, the next false positive is a little bit more complicated
 as there is no evidence I could use attached to it as far as I can tell.

 Suppose there is an expression

 {{{
 foo x = case x of
     A -> ...
     B -> ...
     y -> error $ "foo" ++ (case y of
         C -> "C"
         D -> "D")
 }}}

 This is fine and works as expected. But now GHC decides to float out the
 expression, yielding:

 {{{
 lvl y = error $ "foo" ++ (case y of
     C -> "C"
     D -> "D")

 foo x = case x of
     A -> ...
     B -> ...
     y -> lvl y
 }}}

 I don't see where GHC would record that {{{y}}} can only match {{{C}}} and
 {{{D}}}. I think it doesn't do it anywhere, most likely because no one
 needed that information until today.

 A possible solution might be to look for unexported local functions which
 are non-exhaustive and record the set of allowed constructors for their
 arguments. All calls to such a function would then be required to only
 included the correct possible constructors. Or is there a better way?

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


More information about the ghc-tickets mailing list