c0d508d6c02301e0dceba86be6dc1c88cec000f0
[ghc-hetmet.git] / ghc / lib / ghc / GHCerr.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1994-1996
3 %
4
5 \section[GHCerr]{Module @GHCerr@}
6
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").
9  
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.
13
14 \begin{code}
15 module GHCerr where
16
17 import Prelude
18 import IOBase
19
20 ---------------------------------------------------------------
21 -- HACK: Magic unfoldings not implemented for unboxed lists
22 --       Need to define a "build" to avoid undefined symbol
23 -- in this module to avoid .hi proliferation.
24
25 build   = error "GHCbase.build"
26 augment = error "GHCbase.augment"
27 --{-# GENERATE_SPECS build a #-}
28 --build                 :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
29 --build g       = g (:) []
30
31
32 ---------------------------------------------------------------
33 -- Used for compiler-generated error message;
34 -- encoding saves bytes of string junk.
35
36 absentErr, parError :: a
37 irrefutPatError
38  , noDefaultMethodError
39  , noExplicitMethodError
40  , nonExhaustiveGuardsError
41  , patError
42  , recConError
43  , recUpdError :: String -> a
44
45 absentErr = error "Oops! The program has entered an `absent' argument!\n"
46 parError  = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
47
48 noDefaultMethodError     s = error ("noDefaultMethodError:"++s)
49 noExplicitMethodError    s = error ("No default method for class operation "++s)
50
51 irrefutPatError s           = patError__ (untangle s "irrefutable pattern")
52 nonExhaustiveGuardsError s  = patError__ (untangle s "non-exhaustive guards")
53 patError s                  = patError__ (untangle s "pattern-matching")
54
55 patError__ = error__ (\ x -> _ccall_ PatErrorHdrHook x)
56
57 recConError s = error (untangle s "record constructor")
58 recUpdError s = error (untangle s "record update")
59
60 untangle coded in_str
61   =  "In "     ++ in_str
62   ++ (if null msg then "" else (": " ++ msg))
63   ++ "; at "   ++ file
64   ++ ", line " ++ line
65   ++ "\n"
66   where
67     (file,line,msg)
68       = case (span not_bar coded) of { (f, (_:rest)) ->
69         case (span not_bar rest)  of { (l, (_:m)) ->
70         (f,l,m) }}
71     not_bar c = c /= '|'
72 \end{code}