{-# LANGUAGE DeriveDataTypeable #-}
module Agda.Utils.Impossible where
import Control.Exception as E
data Impossible
= Impossible String Integer
| Unreachable String Integer
| ImpMissingDefinitions [String] String
instance Show Impossible where
show (Impossible file line) = unlines
[ "An internal error has occurred. Please report this as a bug."
, "Location of the error: " ++ file ++ ":" ++ show line
]
show (Unreachable file line) = unlines
[ "We reached a program point we did not want to reach."
, "Location of the error: " ++ file ++ ":" ++ show line
]
show (ImpMissingDefinitions needed forthis) = unlines
[ "The following builtins or primitives need to be bound to use " ++ forthis ++ ":"]
++ unwords needed
instance Exception Impossible
throwImpossible :: Impossible -> a
throwImpossible = throw
catchImpossible :: IO a -> (Impossible -> IO a) -> IO a
catchImpossible = E.catch