2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[PrelErr]{Module @PrelErr@}
7 The PrelErr module defines the code for the wired-in error functions,
8 which have a special type in the compiler (with "open tyvars").
10 We cannot define these functions in a module where they might be used
11 (e.g., PrelBase), because the magical wired-in type will get confused
12 with what the typechecker figures out.
15 {-# OPTIONS -fno-implicit-prelude #-}
19 , noMethodBindingError
20 , nonExhaustiveGuardsError
24 , recUpdError -- :: String -> a
26 , absentErr, parError -- :: a
29 , error -- :: String -> a
30 , assertError -- :: String -> Bool -> a -> a
35 import PrelList ( span )
39 %*********************************************************
41 \subsection{Error-ish functions}
43 %*********************************************************
46 -- error stops execution and displays an error message
48 error s = throw (ErrorCall s)
51 %*********************************************************
53 \subsection{Compiler generated errors + local utils}
55 %*********************************************************
57 Used for compiler-generated error message;
58 encoding saves bytes of string junk.
61 absentErr, parError, seqError :: a
63 absentErr = error "Oops! The program has entered an `absent' argument!\n"
64 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
65 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
71 , noMethodBindingError
72 , nonExhaustiveGuardsError
76 , recUpdError :: String -> a
78 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
79 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
80 nonExhaustiveGuardsError s = throw (NonExhaustiveGuards (untangle s "Non-exhaustive guards in"))
81 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
82 recSelError s = throw (RecSelError (untangle s "Missing field in record selection"))
83 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
84 recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated"))
87 assertError :: String -> Bool -> a -> a
88 assertError str pred v
90 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
95 (untangle coded message) expects "coded" to be of the form
101 location message details
104 untangle :: String -> String -> String
105 untangle coded message
113 = case (span not_bar coded) of { (loc, rest) ->
115 ('|':det) -> (loc, ' ' : det)