1 % -----------------------------------------------------------------------------
2 % $Id: Err.lhs,v 1.4 2002/04/11 12:03:43 simonpj 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 , runtimeError -- :: Addr# -> a -- Addr# points to UTF8 encoded C string
28 , absentErr, parError -- :: a
31 , error -- :: String -> a
32 , assertError -- :: String -> Bool -> a -> a
38 import GHC.List ( span )
42 %*********************************************************
44 \subsection{Error-ish functions}
46 %*********************************************************
49 -- error stops execution and displays an error message
51 error s = throw (ErrorCall s)
53 -- It is expected that compilers will recognize this and insert error
54 -- messages which are more appropriate to the context in which undefined
58 undefined = error "Prelude.undefined"
61 %*********************************************************
63 \subsection{Compiler generated errors + local utils}
65 %*********************************************************
67 Used for compiler-generated error message;
68 encoding saves bytes of string junk.
71 absentErr, parError, seqError :: a
73 absentErr = error "Oops! The program has entered an `absent' argument!\n"
74 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
75 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
79 recSelError, recConError, irrefutPatError, runtimeError,
80 nonExhaustiveGuardsError, patError, noMethodBindingError
81 :: Addr# -> a -- All take a UTF8-encoded C string
83 recSelError s = throw (RecSelError (unpackCStringUtf8# s)) -- No location info unfortunately
84 runtimeError s = error (unpackCStringUtf8# s) -- No location info unfortunately
86 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
87 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
88 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
89 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
90 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
92 assertError :: Addr# -> Bool -> a -> a
93 assertError str pred v
95 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
99 (untangle coded message) expects "coded" to be of the form
105 location message details
108 untangle :: Addr# -> String -> String
109 untangle coded message
116 coded_str = unpackCStringUtf8# coded
119 = case (span not_bar coded_str) of { (loc, rest) ->
121 ('|':det) -> (loc, ' ' : det)