#12489 closed bug (fixed)

undefined in view pattern inside pattern synonym causes GHC to panic

Reported by: pkmx Owned by:
Priority: normal Milestone: 8.0.2
Component: Compiler Version: 8.0.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case: patsyn/should_compile/T12489
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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!

Change History (6)

comment:1 Changed 12 months ago by mpickering

Keywords: PatternSynonyms added

comment:2 Changed 12 months ago by mpickering

This still happens in HEAD.

comment:3 Changed 12 months ago by Simon Peyton Jones <simonpj@…>

In f352e5c/ghc:

Keep the bindings local during defaultCallStacks

defaultCallStacks generates evidence bindings for call stacks,
but wasn't setting the binding site correctly.  As a result
they were simply discarded in the case of pattern synonyms,
giving rise to Trac #12489.

The fix is easy; and I added an ASSERT to catch the error earlier.

comment:4 Changed 12 months ago by simonpj

Status: newmerge
Test Case: patsyn/should_compile/T12489

comment:5 Changed 12 months ago by Ben Gamari <ben@…>

In 829b9682/ghc:

Keep the bindings local during defaultCallStacks

defaultCallStacks generates evidence bindings for call stacks,
but wasn't setting the binding site correctly.  As a result
they were simply discarded in the case of pattern synonyms,
giving rise to Trac #12489.

The fix is easy; and I added an ASSERT to catch the error earlier.

(cherry picked from commit f352e5cd7bb629fe0ca3b913bfbe7bee43d62f3a)

comment:6 Changed 12 months ago by bgamari

Milestone: 8.0.2
Resolution: fixed
Status: mergeclosed
Version: 8.18.0.1
Note: See TracTickets for help on using tickets.