Skip to content

undefined in view pattern inside pattern synonym causes GHC to panic

The following:

{-# LANGUAGE PatternSynonyms, ViewPatterns #-}

pattern P :: a -> b
pattern P a <- (undefined -> a)

causes GHC HEAD and 8.0.1 to panic:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.1.20160813 for x86_64-unknown-linux):
	StgCmmEnv: variable not found

Removing the pattern signature or moving undefined behind another name work however:

{-# LANGUAGE PatternSynonyms, ViewPatterns #-}

bottom :: a
bottom = undefined

pattern P :: a -> b
pattern P a <- (bottom -> a) -- OK!

-- No type signature
pattern P' a <- (undefined -> a) -- OK!
Trac metadata
Trac field Value
Version 8.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information