1 % -----------------------------------------------------------------------------
2 % $Id: PrelErr.lhs,v 1.18 2000/06/30 13:39:35 simonmar Exp $
4 % (c) The University of Glasgow, 1994-2000
7 \section[PrelErr]{Module @PrelErr@}
9 The PrelErr 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., PrelBase), 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
37 import PrelList ( span )
41 %*********************************************************
43 \subsection{Error-ish functions}
45 %*********************************************************
48 -- error stops execution and displays an error message
50 error s = throw (ErrorCall s)
53 %*********************************************************
55 \subsection{Compiler generated errors + local utils}
57 %*********************************************************
59 Used for compiler-generated error message;
60 encoding saves bytes of string junk.
63 absentErr, parError, seqError :: a
65 absentErr = error "Oops! The program has entered an `absent' argument!\n"
66 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
67 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
73 , noMethodBindingError
74 , nonExhaustiveGuardsError
78 , recUpdError :: String -> a
80 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
81 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
82 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
83 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
84 recSelError s = throw (RecSelError (untangle s "Missing field in record selection"))
85 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
86 recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated"))
89 assertError :: String -> Bool -> a -> a
90 assertError str pred v
92 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
97 (untangle coded message) expects "coded" to be of the form
103 location message details
106 untangle :: String -> String -> String
107 untangle coded message
115 = case (span not_bar coded) of { (loc, rest) ->
117 ('|':det) -> (loc, ' ' : det)