Skip to content

erroneous pattern synonym with representation polymorphic existential makes GHC panic

Summary

a pattern synonym type may not mention an existential type variable, this is reported as usual when trying to use types of kind Type, however, when the type mentioned is representation polymorphic, GHC panics on newer GHCs.

Steps to reproduce

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}

module Bug where

import GHC.Exts

pattern Bug :: forall b. (Eq b) => forall {r :: RuntimeRep} (a :: TYPE r). a
pattern Bug <- (undefined -> _unused) 
  where 
    Bug = undefined

Mind that this should not compile anyway; only the panic is unexpected

<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.4.8:
	typeKind
  forall {r :: RuntimeRep} (a :: TYPE r). a
  [r_aNu, a_aNy]
  a_aNy :: TYPE r_aNu
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:182:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/Core/Type.hs:3059:18 in ghc:GHC.Core.Type

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

Expected behavior

show the same error message as with non-representation-polymorphic types ("Quantified type's kind mentions quantified type variable type: ‘forall a. a’")

Environment

  • GHC version used: GHC 9.4.8 / 9.6.4 / 9.8.2
  • does not happen on GHC 9.2.8 / GHC HEAD from 23/03/2024

Optional:

  • Operating System: NixOS
  • System Architecture: x86_64-linux
Edited by Magnus
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information