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