[project @ 1997-03-17 20:34:25 by simonpj]
[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 {-# OPTIONS -fno-implicit-prelude #-}
16 module GHCerr where
17
18 --import Prelude
19 import PrelBase
20 import PrelList ( span )
21 import IOBase
22
23 ---------------------------------------------------------------
24 -- HACK: Magic unfoldings not implemented for unboxed lists
25 --       Need to define a "build" to avoid undefined symbol
26 -- in this module to avoid .hi proliferation.
27
28 build   = error "GHCbase.build"
29 augment = error "GHCbase.augment"
30 --{-# GENERATE_SPECS build a #-}
31 --build                 :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
32 --build g       = g (:) []
33 \end{code}
34
35
36 Used for compiler-generated error message;
37 encoding saves bytes of string junk.
38
39 \begin{code}
40 absentErr, parError :: a
41
42 absentErr = error "Oops! The program has entered an `absent' argument!\n"
43 parError  = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
44 \end{code}
45
46 \begin{code}
47 irrefutPatError
48  , noDefaultMethodError
49  , noExplicitMethodError
50  , nonExhaustiveGuardsError
51  , patError
52  , recConError
53  , recUpdError :: String -> a
54
55 noDefaultMethodError     s = error ("noDefaultMethodError:"++s)
56 noExplicitMethodError    s = error ("No default method for class operation "++s)
57 irrefutPatError          s = error (untangle s "Irrefutable pattern failed for pattern")
58 nonExhaustiveGuardsError s = error (untangle s "Non-exhaustive guards in")
59 patError                 s = error (untangle s "Non-exhaustive patterns in")
60 recConError              s = error (untangle s "Missing field in record construction:")
61 recUpdError              s = error (untangle s "Record to doesn't contain field(s) to be updated")
62 \end{code}
63
64
65 (untangle coded message) expects "coded" to be of the form 
66
67         "location|details"
68
69 It prints
70
71         location message details
72
73 \begin{code}
74 untangle coded message
75   =  location
76   ++ ": " 
77   ++ message
78   ++ details
79   ++ "\n"
80   where
81     (location, details)
82       = case (span not_bar coded) of { (location, rest) ->
83         case rest of
84           ('|':details) -> (location, ' ' : details)
85           _             -> (location, "")
86         }
87     not_bar c = c /= '|'
88 \end{code}
89
90 -- This local variant of "error" calls PatErrorHdrHook instead of ErrorHdrHook,
91 -- but the former does exactly the same as the latter, so I nuked it.
92 --              SLPJ Jan 97
93 -- patError__ = error__ (\ x -> _ccall_ PatErrorHdrHook x)
94