Skip to content

levity-polymorphic strict fields panic

Summary

Using a levity-polymorphic type as a strict field of a data type causes a panic.

Steps to reproduce

Create a file 'Test.hs':

{-# LANGUAGE PolyKinds #-}

module Test where

import GHC.Exts

data Test (a :: TYPE r) = Test !a

Run ghc Test.hs, that gives the following output:

[1 of 1] Compiling Test             ( Test.hs, Test.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.10.1:
	isUnliftedType
  a_ai9[sk:1] :: TYPE r_ai8[sk:1]
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1179:37 in ghc:Outputable
        pprPanic, called at compiler/types/Type.hs:1973:10 in ghc:Type

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

Expected behavior

After removing the strictness annotation I get this normal compilation error:

[1 of 1] Compiling Test             ( Test.hs, Test.o )

Test.hs:7:27: error:
    • A levity-polymorphic type is not allowed here:
        Type: a
        Kind: TYPE r
    • In the definition of data constructor ‘Test’
      In the data type declaration for ‘Test’
  |
7 | data Test (a :: TYPE r) = Test a
  |                           ^^^^^^

Environment

  • GHC version used: 8.10.1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information