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 #-}
20 , noMethodBindingError
21 , nonExhaustiveGuardsError
25 , recUpdError -- :: String -> a
27 , absentErr, parError -- :: a
30 , error -- :: String -> a
31 , ioError -- :: String -> a
32 , assertError -- :: String -> Bool -> a -> a
36 import PrelIOBase ( IO(..), catch )
39 import PrelList ( span )
40 import PrelPack ( packString )
41 import PrelArr ( ByteArray(..) )
43 #ifndef __PARALLEL_HASKELL__
44 import PrelForeign ( StablePtr, deRefStablePtr )
47 ---------------------------------------------------------------
48 -- HACK: Magic unfoldings not implemented for unboxed lists
49 -- Need to define a "build" to avoid undefined symbol
50 -- in this module to avoid .hi proliferation.
52 build = error "GHCbase.build"
53 augment = error "GHCbase.augment"
54 --{-# GENERATE_SPECS build a #-}
55 --build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
59 %*********************************************************
61 \subsection{Error-ish functions}
63 %*********************************************************
69 = case (errorIO# io) of
72 bottom = bottom -- Never evaluated
74 ioError :: String -> a
75 ioError s = error__ ``&IOErrorHdrHook'' s
77 -- error stops execution and displays an error message
79 error s = error__ ``&ErrorHdrHook'' s
81 -- This local variant of "error" calls PatErrorHdrHook instead of ErrorHdrHook,
82 -- but the former does exactly the same as the latter, so I nuked it.
85 -- Hmm..distinguishing between these two kinds of error is quite useful in the
86 -- compiler sources, printing out a more verbose msg in the case of patter
88 -- So I've reinstated patError to invoke its own message function hook again.
90 patError__ x = error__ ``&PatErrorHdrHook'' x
92 error__ :: Addr{-C function pointer to hook-} -> String -> a
95 #ifdef __PARALLEL_HASKELL__
97 (hFlush stdout) `catch` (\ _ -> return ())
98 let bs@(ByteArray (_,len) _) = packString s
99 _ccall_ __writeErrString__ msg_hdr bs len
100 _ccall_ stg_exit (1::Int)
104 (hFlush stdout) `catch` (\ _ -> return ())
105 -- Note: there's potential for trouble here in a
106 -- a concurrent setting if an error is flagged after the
107 -- lock on the stdout handle. (I don't see a possibility
108 -- of this occurring with the current impl, but still.)
109 let bs@(ByteArray (_,len) _) = packString s
110 _ccall_ writeErrString__ msg_hdr bs len
111 errorHandler <- _ccall_ getErrorHandler
112 if errorHandler == (-1::Int) then
113 _ccall_ stg_exit (1::Int)
115 osptr <- _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
116 _ccall_ decrementErrorCount
117 oact <- deRefStablePtr osptr
121 #endif {- !parallel -}
124 %*********************************************************
126 \subsection{Compiler generated errors + local utils}
128 %*********************************************************
130 Used for compiler-generated error message;
131 encoding saves bytes of string junk.
134 absentErr, parError, seqError :: a
136 absentErr = error "Oops! The program has entered an `absent' argument!\n"
137 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
138 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
144 , noMethodBindingError
145 --, noExplicitMethodError
146 , nonExhaustiveGuardsError
150 , recUpdError :: String -> a
152 --noDefaultMethodError s = error ("noDefaultMethodError:"++s)
153 --noExplicitMethodError s = error ("No default method for class operation "++s)
154 noMethodBindingError s = error (untangle s "No instance nor default method for class operation")
155 irrefutPatError s = error (untangle s "Irrefutable pattern failed for pattern")
156 nonExhaustiveGuardsError s = error (untangle s "Non-exhaustive guards in")
157 recSelError s = error (untangle s "Missing field in record selection:")
158 recConError s = error (untangle s "Missing field in record construction:")
159 recUpdError s = error (untangle s "Record to doesn't contain field(s) to be updated")
160 patError s = patError__ (untangle s "Non-exhaustive patterns in")
162 assertError :: String -> Bool -> a -> a
163 assertError str pred v
165 | otherwise = error (untangle str "Assertion failed")
170 (untangle coded message) expects "coded" to be of the form
176 location message details
179 untangle coded message
187 = case (span not_bar coded) of { (location, rest) ->
189 ('|':details) -> (location, ' ' : details)