Skip to content

Panic while printing levity polymorphism error

Program

{-# LANGUAGE UnliftedNewtypes #-}                                               
{-# LANGUAGE ExplicitForAll #-}                                                 
{-# LANGUAGE PolyKinds #-}                                                      
                                                                                
import GHC.Exts                                                                 
                                                                                
newtype Id (a :: TYPE r) = Id a                                                 
                                                                                
foo :: forall r (a :: TYPE r). Id a -> Id a                                     
foo x = x

Output

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.9.0.20191008:
	isUnliftedType
  Id a_a1g7 :: TYPE r_a1g6
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1179:37 in ghc:Outputable
        pprPanic, called at compiler/types/Type.hs:2229:10 in ghc:Type

Expected output

    A levity-polymorphic type is not allowed here:
      Type: Id a
      Kind: TYPE r
    In the type of binder ‘x’

The issue seems to be specific to binders of types that are unlifted newtypes.

Environment

GHC HEAD

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