1 % -----------------------------------------------------------------------------
2 % $Id: Err.lhs,v 1.1 2001/06/28 14:15:03 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 , 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"
81 , noMethodBindingError
82 , nonExhaustiveGuardsError
86 , recUpdError :: String -> a
88 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
89 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
90 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
91 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
92 recSelError s = throw (RecSelError (untangle s "Missing field in record selection"))
93 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
94 recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated"))
97 assertError :: String -> Bool -> a -> a
98 assertError str pred v
100 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
105 (untangle coded message) expects "coded" to be of the form
111 location message details
114 untangle :: String -> String -> String
115 untangle coded message
123 = case (span not_bar coded) of { (loc, rest) ->
125 ('|':det) -> (loc, ' ' : det)