Skip to content

Partially applied type family causes GHC internal error since GHC 8.8

On GHC 8.8.0.20190721, the following program

{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE GADTs               #-}
{-# LANGUAGE PolyKinds           #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies        #-}
{-# LANGUAGE TypeApplications    #-}

module Bug where

import Data.Kind
  ( Type )
import Data.Proxy
  ( Proxy(Proxy) )


data HList :: [Type] -> Type where

type family Foo (xs :: [Type]) (ys :: [Type]) :: [Type] where

foo :: forall (is :: [Type]). HList is -> HList (Foo is)
foo = case Proxy @is of
        _ -> undefined

causes a GHC internal error:

bug.hs:21:50: error:
    * Expecting one more argument to `Foo is'
      Expected kind `[*]', but `Foo is' has kind `[*] -> [*]'
    * In the first argument of `HList', namely `(Foo is)'
      In the type signature:
        foo :: forall (is :: [Type]). HList is -> HList (Foo is)
   |
21 | foo :: forall (is :: [Type]). HList is -> HList (Foo is)
   |

bug.hs:22:19: error:
    * GHC internal error: `is' is not in scope during type checking, but it passed the renamer
      tcl_env of environment: []
    * In the type `is'
      In the expression: Proxy @is
      In the expression: case Proxy @is of { _ -> undefined }
   |
22 | foo = case Proxy @is of
   |                   ^^

On GHC 8.6.5, the internal error does not occur and as expected we simply get an error for a partially applied type family.

bug.hs:21:50: error:
    * Expecting one more argument to `Foo is'
      Expected kind `[*]', but `Foo is' has kind `[*] -> [*]'
    * In the first argument of `HList', namely `(Foo is)'
      In the type signature:
        foo :: forall (is :: [Type]). HList is -> HList (Foo is)
   |
21 | foo :: forall (is :: [Type]). HList is -> HList (Foo is)
   |

This came up after I had modified a type family by adding an extra argument, and had forgotten to pass in that extra argument somewhere.

Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information