[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / lib / prelude / GHCerr.hs
1 {- The GHCerr module defines the code for the
2    wired-in error functions, which have a special
3    type in the compiler (with "open tyvars").
4    
5    We cannot define these functions in a module where they might be
6    used (e.g., GHCbase), because the magical wired-in type will get
7    confused with what the typechecker figures out.
8 -}
9 module GHCerr where
10
11 import GHCbase (error__)
12
13 ---------------------------------------------------------------
14 -- HACK: Magic unfoldings not implemented for unboxed lists
15 --       Need to define a "build" to avoid undefined symbol
16 -- in this module to avoid .hi proliferation.
17
18 build   = error "GHCbase.build"
19 augment = error "GHCbase.augment"
20 --{-# GENERATE_SPECS build a #-}
21 --build                 :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
22 --build g       = g (:) []
23
24
25 ---------------------------------------------------------------
26 cannon_fodder_to_avoid_empty__versions__ = (1::Int)
27
28 -- Used for compiler-generated error message;
29 -- encoding saves bytes of string junk.
30
31 absentErr, parError :: a
32 irrefutPatError
33  , noDefaultMethodError
34  , noExplicitMethodError
35  , nonExhaustiveGuardsError
36  , patError
37  , recConError
38  , recUpdError :: String -> a
39
40 absentErr = error "Oops! The program has entered an `absent' argument!\n"
41 parError  = error "Oops! Entered GHCbase.parError (a GHC bug -- please report it!)\n"
42
43 noDefaultMethodError     s = error ("noDefaultMethodError:"++s)
44 noExplicitMethodError    s = error ("noExplicitMethodError:"++s)
45
46 irrefutPatError s           = patError__ (untangle s "irrefutable pattern")
47 nonExhaustiveGuardsError s  = patError__ (untangle s "non-exhaustive guards")
48 patError s                  = patError__ (untangle s "pattern-matching")
49
50 patError__ = error__ (\ x -> _ccall_ PatErrorHdrHook x)
51
52 recConError s = error (untangle s "record constructor")
53 recUpdError s = error (untangle s "record update")
54
55 untangle coded in_str
56   =  "In "     ++ in_str
57   ++ (if null msg then "" else (": " ++ msg))
58   ++ "; at "   ++ file
59   ++ ", line " ++ line
60   ++ "\n"
61   where
62     (file,line,msg)
63       = case (span not_bar coded) of { (f, (_:rest)) ->
64         case (span not_bar rest)  of { (l, (_:m)) ->
65         (f,l,m) }}
66     not_bar c = c /= '|'