2 {-# OPTIONS -fno-implicit-prelude #-}
3 -----------------------------------------------------------------------------
6 -- Copyright : (c) The University of Glasgow, 1994-2002
7 -- License : see libraries/base/LICENSE
9 -- Maintainer : cvs-ghc@haskell.org
10 -- Stability : internal
11 -- Portability : non-portable (GHC extensions)
13 -- The "GHC.Err" module defines the code for the wired-in error functions,
14 -- which have a special type in the compiler (with \"open tyvars\").
16 -- We cannot define these functions in a module where they might be used
17 -- (e.g., "GHC.Base"), because the magical wired-in type will get confused
18 -- with what the typechecker figures out.
20 -----------------------------------------------------------------------------
25 , noMethodBindingError
26 , nonExhaustiveGuardsError
30 , runtimeError -- :: Addr# -> a -- Addr# points to UTF8 encoded C string
32 , absentErr, parError -- :: a
35 , error -- :: String -> a
36 , assertError -- :: String -> Bool -> a -> a
43 import GHC.List ( span )
48 %*********************************************************
50 \subsection{Error-ish functions}
52 %*********************************************************
55 -- error stops execution and displays an error message
57 error s = throw (ErrorCall s)
59 -- It is expected that compilers will recognize this and insert error
60 -- messages which are more appropriate to the context in which undefined
64 undefined = error "Prelude.undefined"
67 %*********************************************************
69 \subsection{Compiler generated errors + local utils}
71 %*********************************************************
73 Used for compiler-generated error message;
74 encoding saves bytes of string junk.
77 absentErr, parError, seqError :: a
79 absentErr = error "Oops! The program has entered an `absent' argument!\n"
80 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
81 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
85 recSelError, recConError, irrefutPatError, runtimeError,
86 nonExhaustiveGuardsError, patError, noMethodBindingError
87 :: Addr# -> a -- All take a UTF8-encoded C string
89 recSelError s = throw (RecSelError (unpackCStringUtf8# s)) -- No location info unfortunately
90 runtimeError s = error (unpackCStringUtf8# s) -- No location info unfortunately
92 nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in"))
93 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
94 recConError s = throw (RecConError (untangle s "Missing field in record construction"))
95 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
96 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
98 assertError :: Addr# -> Bool -> a -> a
99 assertError str pred v
101 | otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
105 (untangle coded message) expects "coded" to be of the form
111 location message details
114 untangle :: Addr# -> String -> String
115 untangle coded message
122 coded_str = unpackCStringUtf8# coded
125 = case (span not_bar coded_str) of { (loc, rest) ->
127 ('|':det) -> (loc, ' ' : det)