Opened 3 years ago

Closed 2 years ago

#12104 closed bug (fixed)

Type families, `TypeError`, and `-fdefer-type-errors` cause "opt_univ fell into a hole"

Reported by: antalsz Owned by:
Priority: high Milestone: 8.2.1
Component: Compiler (Type checker) Version: 8.0.1
Keywords: TypeFamilies, CustomTypeErrors Cc:…, conal, kosmikus
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: #13487 Differential Rev(s): Phab:D3495
Wiki Page:

Description (last modified by thomie)

If I create a type family – open or closed – with a case that evaluates to a TypeError, and define a top-level binding with this type, loading the file with -fdefer-type-errors enabled (or via :load!/:reload!) panics GHC with "opt_univ fell into a hole". (And if I used :load! or :reload!, -fdefer-type-errors doesn't get unset.)

A minimal example:

{-# LANGUAGE TypeFamilies, DataKinds, UndecidableInstances #-}

module T12104 where

import GHC.TypeLits

type family F a where
  F a = TypeError (Text "error")

err :: F ()
err = ()

results in the panic

….hs:9:7: warning: [-Wdeferred-type-errors]
    • error
    • In the expression: ()
      In an equation for ‘err’: err = ()
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.1 for x86_64-apple-darwin):
	opt_univ fell into a hole {a4Va}

Adding more cases to the type family, or making it open, still cause the crash. This holds whether the error case is a final catch-all case, or something more like

type family F a where
  F () = TypeError (Text "error")
  F a  = ()

Just using a type synonym for F doesn't cause a panic, however, and nor does giving err the type TypeError (Text "error") directly.

Attachments (1)

type-families-TypeError-defer-type-errors-opt_univ-bug.hs (162 bytes) - added by antalsz 3 years ago.
The minimal example contained in the text of the ticket

Download all attachments as: .zip

Change History (12)

Changed 3 years ago by antalsz

The minimal example contained in the text of the ticket

comment:1 Changed 3 years ago by thomie

Architecture: x86_64 (amd64)Unknown/Multiple
Description: modified (diff)
Operating System: MacOS XUnknown/Multiple
Priority: normalhigh

Confirmed with HEAD (8.1.20160520).

Also reproducible by running just

ghc -fdefer-type-errors type-families-TypeError-defer-type-errors-opt_univ-bug.hs

comment:2 Changed 3 years ago by thomie

Cc: conal added
Component: CompilerCompiler (Type checker)

Conal Elliott reported the same panic in, when writing a custom GHC plugin.

comment:3 Changed 2 years ago by kosmikus

Cc: kosmikus added

comment:5 Changed 2 years ago by simonpj

Works ok in HEAD. I don't have an 8.2 branch to hand to check.

Can someone add this as a regression test, pls?


comment:6 Changed 2 years ago by kosmikus

Simon, thanks a lot for testing with HEAD. I can confirm that my code works with HEAD (8.3.20170422) as well, but it still crashes with

comment:7 Changed 2 years ago by simonpj

Could be the fix to #12156 (unlikely), or #13381 (more likely), or #13487. I'm not sure which of these are merged.

comment:8 Changed 2 years ago by RyanGlScott

I've confirmed that 2f9f1f86849ebc18af409c9b3fd809c9cd464021 (the fix for #13487) fixes this program as well. Curiously, #13487 was marked as merge, but hasn't made it into 8.2 for some reason. Can we do so?

I'll prepare a regression test.

comment:9 Changed 2 years ago by RyanGlScott

Differential Rev(s): Phab:D3495
Status: newpatch

comment:10 Changed 2 years ago by Ben Gamari <ben@…>

In 69b9b853/ghc:

Add regression test for #12104

Commit 2f9f1f86849ebc18af409c9b3fd809c9cd464021
(#13487) fixes #12104 as well. This adds a regression test for the
program reported in #12104 to keep it fixed.

Test Plan: make test TEST=T12104

Reviewers: bgamari, austin

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #12104

Differential Revision:

comment:11 Changed 2 years ago by bgamari

Milestone: 8.2.1
Resolution: fixed
Status: patchclosed

Will merge fix for #13487 to 8.2.

Note: See TracTickets for help on using tickets.