[GHC] #13952: Liberal coverage condition fails if TypeInType is enabled

GHC ghc-devs at haskell.org
Mon Jul 10 15:59:11 UTC 2017


#13952: Liberal coverage condition fails if TypeInType is enabled
-------------------------------------+-------------------------------------
        Reporter:  mpickering        |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1-rc2
      Resolution:  fixed             |             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:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * status:  new => closed
 * resolution:   => fixed


Comment:

 This is expected behavior (see
 [https://github.com/GetShopTV/swagger2/issues/95 here] for another place
 where a similar issue arose). The difference between GHC 8.0 and 8.2 is
 that the datatypes in `GHC.Generics` are now poly-kinded. As a result, the
 kinds involved in `Expected` are generalized even further: the return kind
 of `Expected U1` does not determine the kind of `k` in `U1`'s kind (`k ->
 Type`), causing the liberal coverage condition to fail. This is more
 apparent if you turn on `-fprint-explicit-kinds`:

 {{{
 $ /opt/ghc/8.2.1/bin/ghci Foo.hs -fprint-explicit-kinds
 GHCi, version 8.2.0.20170704: http://www.haskell.org/ghc/  :? for help
 Loaded GHCi configuration from /home/rgscott/.ghci
 [1 of 1] Compiling Bookkeeper.Internal ( Foo.hs, interpreted )

 Foo.hs:19:10: error:
     • Illegal instance declaration for ‘FromGeneric k (U1 k) book’
         The liberal coverage condition fails in class ‘FromGeneric’
           for functional dependency: ‘a -> book’
         Reason: lhs type ‘U1 k’ does not determine rhs type ‘book’
         Un-determined variable: book
     • In the instance declaration for ‘FromGeneric U1 book’
    |
 19 | instance (book ~ Expected U1) => FromGeneric U1 book where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }}}

 This also explains why turning off `TypeInType` fixes the issue, since
 this kind generalization doesn't occur, and all of the kind variables
 simply default to `Type`.

 A simple way to fix this is to just be more explicit about what kinds to
 use in `Expected`:

 {{{#!hs
 type family Expected (a :: k -> Type) :: k where
   Expected ((l :+: r) :: k -> Type) = (TypeError ('Text "Cannot convert
 sum types into Books") :: k)
   Expected (U1        :: k -> Type) = (TypeError ('Text "Cannot convert
 non-record types into Books") :: k)
 }}}

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


More information about the ghc-tickets mailing list