Panic on COMPLETE pragma with mismatched type variable order
The motivating example is to allow patterns with phantom types to interact nicely with TypeApplications, so in the below we can do L @Int :: a -> L a Int
to specify the phantom.
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ExplicitForAll #-}
data E a b = L' a | R b
pattern L :: forall b a. a -> E a b
pattern L a = L' a
{-# COMPLETE L, R #-}
Issues occur when nesting cases
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
testMono :: E (E Int Int) Int -> Int
testMono x = case x of
L (L _) -> 0
L (R _) -> 1
R _ -> 2
And GHC panics when polymorphic
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
testPoly :: E (E a b) c -> Int
testPoly x = case x of
L (L _) -> 0
L (R _) -> 1
R _ -> 2
The compiler balks
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.1 for x86_64-unknown-linux):
mkOneConFull: Not TyConApp:
c_a50V
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
pprPanic, called at compiler/deSugar/Check.hs:976:30 in ghc:Check
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
So it seems like there's two related issues here:
- The COMPLETE pragma does not work in nesting for out-of-order type variables
- Some printing logic is missing for the error in this polymorphic case
Note that if we define
pattern L :: forall a b. a -> E a b
pattern L a = L' a
Note that we do not get the incomplete warning or the panic, so it seems directly related to the order of the variables, rather than explicit quantification in general