Skip to content

Panic during tyConAppArgs

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}

import Data.Functor.Identity

data HideArg f where
  HideArg :: f a -> HideArg f

data family App :: tF -> tF
data instance App f x = App1 (f x)

class WrappedIn s a | s -> a where
  unwrap :: s -> a

instance WrappedIn (App f a) (f a) where
  unwrap (App1 fa) = fa

pattern Unwrapped :: WrappedIn s a => a -> s
pattern Unwrapped x <- (unwrap -> x)
{-# COMPLETE Unwrapped :: App #-}

boom :: HideArg (App Identity) -> Bool
boom (HideArg (Unwrapped (Identity _))) = True

main :: IO ()
main = print ":("

When I run ghc on the above file, either v8.5 or v8.8, I get:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.8.1 for x86_64-unknown-linux):
	tyConAppArgs
  a_a11i
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
        pprPanic, called at compiler/types/Type.hs:1181:50 in ghc:Type

Interestingly, removing just about any of the parts in the above repro will allow compilation to proceed. Even changing the definition of boom to boom (HideArg (Unwrapped _)) = True dodges the crash. As does removing the COMPLETE pragma.

(Possibly related to #16348 (closed)?)

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