Skip to content

GHC internal error when combining TLKSs and deriving

GHC freaks out when given this code:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TopLevelKindSignatures #-}
module Bug where

import Data.Kind

class C (a :: Type) (b :: Type)

type T :: a -> Type
data T (x :: z) deriving (C z)
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:12:29: error:
    • GHC internal error: ‘z’ is not in scope during type checking, but it passed the renamer
      tcl_env of environment: [as1 :-> Type variable ‘a’ = a :: *,
                               aWI :-> Type variable ‘x’ = x :: a]
    • In the first argument of ‘C’, namely ‘z’
      In the data declaration for ‘T’
   |
12 | data T (x :: z) deriving (C z)
   |                             ^

The code works as written if the TLKS is omitted.

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