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 , noMethodBindingError
21 , nonExhaustiveGuardsError
24 , recUpdError -- :: String -> a
26 , absentErr, parError -- :: a
29 , error -- :: String -> a
30 , ioError -- :: String -> a
31 , assert__ -- :: String -> Bool -> a -> a
38 import Foreign ( StablePtr, deRefStablePtr )
39 import PrelList ( span )
42 ---------------------------------------------------------------
43 -- HACK: Magic unfoldings not implemented for unboxed lists
44 -- Need to define a "build" to avoid undefined symbol
45 -- in this module to avoid .hi proliferation.
47 build = error "GHCbase.build"
48 augment = error "GHCbase.augment"
49 --{-# GENERATE_SPECS build a #-}
50 --build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
54 %*********************************************************
56 \subsection{Error-ish functions}
58 %*********************************************************
64 = case (errorIO# io) of
67 bottom = bottom -- Never evaluated
69 ioError :: String -> a
70 ioError s = error__ ( \ x -> _ccall_ IOErrorHdrHook x ) s
72 -- error stops execution and displays an error message
74 error s = error__ ( \ x -> _ccall_ ErrorHdrHook x ) s
76 error__ :: (Addr{-FILE *-} -> IO ()) -> String -> a
79 #ifdef __PARALLEL_HASKELL__
80 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
81 _ccall_ fflush sTDERR >>
83 _ccall_ fflush sTDERR >>
84 _ccall_ stg_exit (1::Int)
87 = errorIO (msg_hdr sTDERR{-msg hdr-} >>
88 _ccall_ fflush sTDERR >>
90 _ccall_ fflush sTDERR >>
91 _ccall_ getErrorHandler >>= \ errorHandler ->
92 if errorHandler == (-1::Int) then
93 _ccall_ stg_exit (1::Int)
95 _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
97 _ccall_ decrementErrorCount >>= \ () ->
98 deRefStablePtr osptr >>= \ oact ->
101 #endif {- !parallel -}
103 sTDERR = (``stderr'' :: Addr)
106 %*********************************************************
108 \subsection{Compiler generated errors + local utils}
110 %*********************************************************
112 Used for compiler-generated error message;
113 encoding saves bytes of string junk.
116 absentErr, parError, seqError :: a
118 absentErr = error "Oops! The program has entered an `absent' argument!\n"
119 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
120 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
126 , noMethodBindingError
127 --, noExplicitMethodError
128 , nonExhaustiveGuardsError
131 , recUpdError :: String -> a
133 --noDefaultMethodError s = error ("noDefaultMethodError:"++s)
134 --noExplicitMethodError s = error ("No default method for class operation "++s)
135 noMethodBindingError s = error (untangle s "No instance nor default method for class operation")
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)