2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[GHCerr]{Module @GHCerr@}
7 The GHCerr 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., GHCbase), because the magical wired-in type will get confused
12 with what the typechecker figures out.
15 {-# OPTIONS -fno-implicit-prelude #-}
20 , noDefaultMethodError
21 , noExplicitMethodError
22 , 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 Foreign ( StablePtr, deRefStablePtr )
40 import PrelList ( span )
43 ---------------------------------------------------------------
44 -- HACK: Magic unfoldings not implemented for unboxed lists
45 -- Need to define a "build" to avoid undefined symbol
46 -- in this module to avoid .hi proliferation.
48 build = error "GHCbase.build"
49 augment = error "GHCbase.augment"
50 --{-# GENERATE_SPECS build a #-}
51 --build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
55 %*********************************************************
57 \subsection{Error-ish functions}
59 %*********************************************************
65 = case (errorIO# io) of
68 bottom = bottom -- Never evaluated
70 ioError :: String -> a
71 ioError s = error__ ( \ x -> _ccall_ IOErrorHdrHook x ) s
73 -- error stops execution and displays an error message
75 error s = error__ ( \ x -> _ccall_ ErrorHdrHook x ) s
77 error__ :: (Addr{-FILE *-} -> IO ()) -> String -> a
80 #ifdef __PARALLEL_HASKELL__
81 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
82 _ccall_ fflush sTDERR >>
84 _ccall_ fflush sTDERR >>
85 _ccall_ stg_exit (1::Int)
88 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
89 _ccall_ fflush sTDERR >>
91 _ccall_ fflush sTDERR >>
92 _ccall_ getErrorHandler >>= \ errorHandler ->
93 if errorHandler == (-1::Int) then
94 _ccall_ stg_exit (1::Int)
96 _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
98 _ccall_ decrementErrorCount >>= \ () ->
99 deRefStablePtr osptr >>= \ oact ->
102 #endif {- !parallel -}
104 sTDERR = (``stderr'' :: Addr)
107 %*********************************************************
109 \subsection{Compiler generated errors + local utils}
111 %*********************************************************
113 Used for compiler-generated error message;
114 encoding saves bytes of string junk.
117 absentErr, parError, seqError :: a
119 absentErr = error "Oops! The program has entered an `absent' argument!\n"
120 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
121 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
127 , noDefaultMethodError
128 , noExplicitMethodError
129 , nonExhaustiveGuardsError
132 , recUpdError :: String -> a
134 noDefaultMethodError s = error ("noDefaultMethodError:"++s)
135 noExplicitMethodError s = error ("No default method for class operation "++s)
136 irrefutPatError s = error (untangle s "Irrefutable pattern failed for pattern")
137 nonExhaustiveGuardsError s = error (untangle s "Non-exhaustive guards in")
138 patError s = error (untangle s "Non-exhaustive patterns in")
139 recConError s = error (untangle s "Missing field in record construction:")
140 recUpdError s = error (untangle s "Record to doesn't contain field(s) to be updated")
143 assert__ :: String -> Bool -> a -> a
146 | otherwise = error (untangle str "Assertion failed")
151 (untangle coded message) expects "coded" to be of the form
157 location message details
160 untangle coded message
168 = case (span not_bar coded) of { (location, rest) ->
170 ('|':details) -> (location, ' ' : details)
176 -- This local variant of "error" calls PatErrorHdrHook instead of ErrorHdrHook,
177 -- but the former does exactly the same as the latter, so I nuked it.
179 -- patError__ = error__ (\ x -> _ccall_ PatErrorHdrHook x)