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

GHC ghc-devs at haskell.org
Mon Feb 22 10:48:53 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 simonpj):

 Transferred from ghc-defs list
 I am currently giving #11475 a try. However I hit a few problems and
 wanted to ask for a bit of advice about how to proceed.

 I already can handle the following:
 {{{
 case x of
   A y -> e1
   _   -> ....(case x of
                 B -> r2
                 C -> r3) ...
 }}}
 My first problem then was the following construct:
 {{{
 case (case ... of ... -> Left x) of
   Left y -> ...
 }}}
 Or more simple:
 {{{
 case Left x of
   Left y -> ...
 }}}
 So I have to check which constructors the scrutinee may return. I know the
 simplifier has to implement such logic somewhere but did not want to use
 the implementation for two reasons:
  - I didn't know where to find it
  - If GHC uses the same test to prune impossible alternatives and to check
 if they were pruned correctly, extending the linter is useless. A bug in
 the test code will cause also cause a bug in the linter.

 So I implemented such a test myself, but now I am stuck at something like
 this:
 {{{
 foo a b = a : b

 bar = ... case foo a b of
   (:) x y -> ...
 }}}
 I cannot see through `foo`, so I assume it may return `(:)` and `[]`. The
 simplifier on the other hand is able to see through foo and did remove the
 `[]` case, causing my current implementation to throw an incorrect lint
 error.

 How can I get a list/set of all possible `AltCons` returned by a
 function/constant? Or a list of the impossible ones? I tried to get some
 information from the unfolding of a variable, but it seems like unfoldings
 are only attached to top-level names.

 Jonas

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


More information about the ghc-tickets mailing list