1 % -----------------------------------------------------------------------------
2 % $Id: Err.lhs,v 1.3 2001/07/31 13:11:40 simonmar Exp $
4 % (c) The University of Glasgow, 1994-2000
7 \section[GHC.Err]{Module @GHC.Err@}
9 The GHC.Err module defines the code for the wired-in error functions,
10 which have a special type in the compiler (with "open tyvars").
12 We cannot define these functions in a module where they might be used
13 (e.g., GHC.Base), because the magical wired-in type will get confused
14 with what the typechecker figures out.
17 {-# OPTIONS -fno-implicit-prelude #-}
21 , noMethodBindingError
22 , nonExhaustiveGuardsError
26 , recUpdError -- :: String -> a
28 , absentErr, parError -- :: a
31 , errorCString -- :: Addr# -> a -- Arg is a ptr to C string
32 , error -- :: String -> a
33 , assertError -- :: String -> Bool -> a -> a
39 import GHC.List ( span )
43 %*********************************************************
45 \subsection{Error-ish functions}
47 %*********************************************************
50 -- error stops execution and displays an error message
52 error s = throw (ErrorCall s)
54 errorCString :: Addr# -> a
55 errorCString s = error (unpackCString# s)
57 -- It is expected that compilers will recognize this and insert error
58 -- messages which are more appropriate to the context in which undefined
62 undefined = error "Prelude.undefined"
65 %*********************************************************
67 \subsection{Compiler generated errors + local utils}
69 %*********************************************************
71 Used for compiler-generated error message;
72 encoding saves bytes of string junk.
75 absentErr, parError, seqError :: a
77 absentErr = error "Oops! The program has entered an `absent' argument!\n"
78 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
79 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
85 , noMethodBindingError
86 , nonExhaustiveGuardsError
90 , recUpdError :: String -> a
92 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
93 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
94 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
95 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
96 recSelError s = throw (RecSelError (untangle s "Missing field in record selection"))
97 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
98 recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated"))
101 assertError :: String -> Bool -> a -> a
102 assertError str pred v
104 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
109 (untangle coded message) expects "coded" to be of the form
115 location message details
118 untangle :: String -> String -> String
119 untangle coded message
127 = case (span not_bar coded) of { (loc, rest) ->
129 ('|':det) -> (loc, ' ' : det)