Subject: [GHC] #13076: GHC panics can cause text-formatting changes from colorized error messages to linger
From: "GHC" <[email-masked]>
Cc: [email-masked]
Date: Fri, 06 Jan 2017 15:52:12 -0000

#13076: GHC panics can cause text-formatting changes from colorized error messages
to linger
-------------------------------------+-------------------------------------
           Reporter:  RyanGlScott    |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Other
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:  #8809, #12785
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 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 508811004d1806b28a91c3ff4a5c2247e2ad4655, and if #12785 is
 fixed, then this won't be reproducible anymore. If I compile this program
 from #12785:

 {{{#!hs
 {-# 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:

 {{{
 #!html
 <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.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13076>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler