Skip to content

GHC panics can cause text-formatting changes from colorized error messages to linger

This bug relies on GHC panicking right after emitting a normal error message, so take note that I reproduced this error using a GHC HEAD build at commit 50881100, and if #12785 (closed) is fixed, then this won't be reproducible anymore. If I compile this program from #12785 (closed):

{-# LANGUAGE RankNTypes, TypeInType, TypeOperators, KindSignatures, ViewPatterns #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds, GADTs #-}

module Tree where

import Data.Kind

data Peano = Z | S Peano

data HTree n a where
  Point :: a -> HTree Z a
  Leaf :: HTree (S n) a
  Branch :: a -> HTree n (HTree (S n) a) -> HTree (S n) a

data STree n :: forall a . (a -> *) -> HTree n a -> * where
  SPoint :: f a -> STree Z f (Point a)
  SLeaf :: STree (S n) f Leaf
  SBranch :: f a -> STree n (STree (S n) f) stru -> STree (S n) f (a `Branch` stru)
  SBranchX :: (Payload (S n) (Payload n stru) ~ a)
          => f a -> STree n (STree (S n) f) stru -> STree (S n) f (a `Branch` stru)

data Hidden :: Peano -> (a -> *) -> * where
  Hide :: STree n f s -> Hidden n f

nest :: HTree m (Hidden (S m) f) -> Hidden m (STree ('S m) f)
nest (Point (Hide st)) = Hide (SPoint st)
nest Leaf = Hide SLeaf
nest (Hide a `Branch` (nest . hmap nest -> Hide tr)) = Hide $ a `SBranchX` tr

hmap :: (x -> y) -> HTree n x -> HTree n y
hmap f (Point a) = Point (f a)
hmap f Leaf = Leaf
hmap f (a `Branch` tr) = f a `Branch` hmap (hmap f) tr

type family Payload (n :: Peano) (s :: HTree n x) where
  Payload Z (Point a) = a
  Payload (S n) (a `Branch` stru) = a

then something horrible happens to my terminal:

<pre>rgscott@gearloose:~/Software$ ghc/inplace/bin/ghc-stage2 Bug2.hs
[1 of 1] Compiling Tree             ( Bug2.hs, Bug2.o )

<strong>Bug2.hs:29:63: <span style="color: red">error:</span>ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.1.20170105 for x86_64-unknown-linux):
        tcTyVarDetails
  cobox0_aKm :: (m_aJV[sk:2] :: Peano) ~# ('S n_aKl[ssk:3] :: Peano)
  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/basicTypes/Var.hs:480:22 in ghc:Var

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

rgscott@gearloose:~/Software$</strong></pre>

The bold text for error messages kicks in, and never goes away! I have to type tput sgr0 into my terminal in order to get the bold text to go away.

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 Rufflewind
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information