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 , assert__ -- :: String -> Bool -> a -> a
39 import PrelList ( span )
41 #ifndef __PARALLEL_HASKELL__
42 import PrelForeign ( StablePtr, deRefStablePtr )
45 ---------------------------------------------------------------
46 -- HACK: Magic unfoldings not implemented for unboxed lists
47 -- Need to define a "build" to avoid undefined symbol
48 -- in this module to avoid .hi proliferation.
50 build = error "GHCbase.build"
51 augment = error "GHCbase.augment"
52 --{-# GENERATE_SPECS build a #-}
53 --build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
57 %*********************************************************
59 \subsection{Error-ish functions}
61 %*********************************************************
67 = case (errorIO# io) of
70 bottom = bottom -- Never evaluated
72 ioError :: String -> a
73 ioError s = error__ ( \ x -> _ccall_ IOErrorHdrHook x ) s
75 -- error stops execution and displays an error message
77 error s = error__ ( \ x -> _ccall_ ErrorHdrHook x ) s
79 error__ :: (Addr{-FILE *-} -> IO ()) -> String -> a
82 #ifdef __PARALLEL_HASKELL__
83 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
84 _ccall_ fflush sTDERR >>
86 _ccall_ fflush sTDERR >>
87 _ccall_ stg_exit (1::Int)
90 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
91 _ccall_ fflush sTDERR >>
93 _ccall_ fflush sTDERR >>
94 _ccall_ getErrorHandler >>= \ errorHandler ->
95 if errorHandler == (-1::Int) then
96 _ccall_ stg_exit (1::Int)
98 _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
100 _ccall_ decrementErrorCount >>= \ () ->
101 deRefStablePtr osptr >>= \ oact ->
104 #endif {- !parallel -}
106 sTDERR = (``stderr'' :: Addr)
109 %*********************************************************
111 \subsection{Compiler generated errors + local utils}
113 %*********************************************************
115 Used for compiler-generated error message;
116 encoding saves bytes of string junk.
119 absentErr, parError, seqError :: a
121 absentErr = error "Oops! The program has entered an `absent' argument!\n"
122 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
123 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
129 , noMethodBindingError
130 --, noExplicitMethodError
131 , nonExhaustiveGuardsError
135 , recUpdError :: String -> a
137 --noDefaultMethodError s = error ("noDefaultMethodError:"++s)
138 --noExplicitMethodError s = error ("No default method for class operation "++s)
139 noMethodBindingError s = error (untangle s "No instance nor default method for class operation")
140 irrefutPatError s = error (untangle s "Irrefutable pattern failed for pattern")
141 nonExhaustiveGuardsError s = error (untangle s "Non-exhaustive guards in")
142 patError s = error (untangle s "Non-exhaustive patterns in")
143 recSelError s = error (untangle s "Missing field in record selection:")
144 recConError s = error (untangle s "Missing field in record construction:")
145 recUpdError s = error (untangle s "Record to doesn't contain field(s) to be updated")
148 assert__ :: String -> Bool -> a -> a
151 | otherwise = error (untangle str "Assertion failed")
156 (untangle coded message) expects "coded" to be of the form
162 location message details
165 untangle coded message
173 = case (span not_bar coded) of { (location, rest) ->
175 ('|':details) -> (location, ' ' : details)
181 -- This local variant of "error" calls PatErrorHdrHook instead of ErrorHdrHook,
182 -- but the former does exactly the same as the latter, so I nuked it.
184 -- patError__ = error__ (\ x -> _ccall_ PatErrorHdrHook x)