Skip to content

GHC panic: Non-exhaustive patterns in function printTarget

When running ghci or ghc on Translator.hs (given below) and running it, they crash with a panic.

$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 6.10.1
$ ghci -package ghc Translator.hs 
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.0 ... linking ... done.
Loading package filepath-1.1.0.1 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.1 ... linking ... done.
Loading package unix-2.3.1.0 ... linking ... done.
Loading package directory-1.0.0.2 ... linking ... done.
Loading package pretty-1.0.1.0 ... linking ... done.
Loading package process-1.0.1.0 ... linking ... done.
Loading package Cabal-1.6.0.1 ... linking ... done.
Loading package bytestring-0.9.1.4 ... linking ... done.
Loading package editline-0.2.1.0 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package hpc-0.5.0.2 ... linking ... done.
Loading package packedstring-0.1.0.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package ghc-6.10.1 ... linking ... done.
[1 of 1] Compiling Main             ( Translator.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Loading package ghc-paths-0.1.0.5 ... linking ... done.
<interactive>: panic! (the 'impossible' happened)
  (GHC version 6.10.1 for i386-unknown-linux):
        Translator.hs:(20,0)-(21,16): Non-exhaustive patterns in function printTarget


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

*** Exception: ExitFailure 1
*Main>

and ghc:

$ ghc -L/usr/local/ghc-6.10.1/lib/ghc-paths-0.1.0.5/ghc-6.10.1 -lHSghc-paths-0.1.0.5 -package ghc Translator.hs
$ ./a.out 
a.out: panic! (the 'impossible' happened)
  (GHC version 6.10.1 for i386-unknown-linux):
        Translator.hs:(20,0)-(21,16): Non-exhaustive patterns in function printTarget


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

The file is based on the GHC as a library example and tries to extract some data from a Target, which fails. It can probably be reduced somewhat, but I'm still too much stumbling around to effecitvely do this. The file that's being compiled ("noexist.hs" in the file) need not exist, but results are not any different when it does.

Here's Translator.hs:

module Main(main) where
import GHC
import MonadUtils ( liftIO )
import Outputable ( showSDoc, ppr )
import GHC.Paths ( libdir )
import DynFlags ( defaultDynFlags )
 
main = 
                do
                        defaultErrorHandler defaultDynFlags $ do
                                runGhc (Just libdir) $ do
                                        dflags <- getSessionDynFlags
                                        setSessionDynFlags dflags
                                        target <- guessTarget "noexist.hs" Nothing
                                        --liftIO (print (showSDoc (ppr (target))))
                                        liftIO $ printTarget target
                                        setTargets [target]
                                        load LoadAllTargets

printTarget (Target id obj (Just (buf, time))) =
        print $ show buf
Trac metadata
Trac field Value
Version 6.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
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