Opened 3 weeks ago

Closed 3 weeks ago

#14326 closed bug (fixed)

Panic on COMPLETE pragma with mismatched type variable order

Reported by: dailectic Owned by: RyanGlScott
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.2.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: Compile-time crash or panic Test Case: patsyn/should_compile/T14326
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by dailectic)

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:

  1. The COMPLETE pragma does not work in nesting for out-of-order type variables
  2. 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

Change History (8)

comment:1 Changed 3 weeks ago by RyanGlScott

I feel like you're leaving out some important information here. I tried loading this file (I had to add some language extensions that you left out):

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Bug where

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 #-}

I compiled this with 8.2.1, but it did not panic. What am I missing?

comment:2 Changed 3 weeks ago by dailectic

Description: modified (diff)

comment:3 Changed 3 weeks ago by dailectic

Description: modified (diff)

comment:4 in reply to:  1 Changed 3 weeks ago by dailectic

Replying to RyanGlScott:

I feel like you're leaving out some important information here. I tried loading this file (I had to add some language extensions that you left out):

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Bug where

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 #-}

I compiled this with 8.2.1, but it did not panic. What am I missing?

Thanks, I was mistaken and the source seems to be in interaction with nested pattern matches rather than just the declaration. I've edited the ticket to reflect this.

comment:5 Changed 3 weeks ago by RyanGlScott

Keywords: PatternSynonyms added

Thanks for the update. Interestingly, this does not panic on GHC HEAD, which in some ways makes this like an inverse of #14135 (which panics with a mkOneConFull error on HEAD, but not 8.2.1).

comment:6 Changed 3 weeks ago by RyanGlScott

Owner: set to RyanGlScott

Sure enough, the commit that fixed this bug (but also introduced the bug in #14135) was 6b77914cd37b697354611bcd87897885c1e5b4a6 (Fix instantiation of pattern synonyms). I'll add a regression test.

comment:7 Changed 3 weeks ago by Ryan Scott <ryan.gl.scott@…>

In 429fafb5/ghc:

Add regression test for #14326

Commit 6b77914cd37b697354611bcd87897885c1e5b4a6 wound up
fixing #14326. Let's add a regression test so that it stays
that way.

comment:8 Changed 3 weeks ago by RyanGlScott

Milestone: 8.4.1
Resolution: fixed
Status: newclosed
Test Case: patsyn/should_compile/T14326
Note: See TracTickets for help on using tickets.