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 )
40 %*********************************************************
42 \subsection{Error-ish functions}
44 %*********************************************************
47 -- error stops execution and displays an error message
49 error s = throw (ErrorCall s)
52 %*********************************************************
54 \subsection{Compiler generated errors + local utils}
56 %*********************************************************
58 Used for compiler-generated error message;
59 encoding saves bytes of string junk.
62 absentErr, parError, seqError :: a
64 absentErr = error "Oops! The program has entered an `absent' argument!\n"
65 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
66 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
72 , noMethodBindingError
73 , nonExhaustiveGuardsError
77 , recUpdError :: String -> a
79 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
80 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
81 nonExhaustiveGuardsError s = throw (NonExhaustiveGuards (untangle s "Non-exhaustive guards in"))
82 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
83 recSelError s = throw (RecSelError (untangle s "Missing field in record selection"))
84 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
85 recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated"))
88 assertError :: String -> Bool -> a -> a
89 assertError str pred v
91 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
96 (untangle coded message) expects "coded" to be of the form
102 location message details
105 untangle :: String -> String -> String
106 untangle coded message
114 = case (span not_bar coded) of { (loc, rest) ->
116 ('|':det) -> (loc, ' ' : det)