2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[ErrsRn]{Reporting errors from the renamer}
6 This is an internal module---access to these functions is through
10 #include "HsVersions.h"
14 import AbsSyn -- we print a bunch of stuff in here
15 import AbsUniType ( TyVarTemplate )
16 import UniType ( UniType(..) )
17 -- UniType is concrete, to make some errors
20 import Name ( cmpName )
22 import Pretty -- to pretty-print error messages
23 import SrcLoc ( mkUnknownSrcLoc, SrcLoc )
28 badClassOpErr :: Name{-class-} -> ProtoName{-op-} -> SrcLoc -> Error
29 -- Class op expected but something else found
30 badClassOpErr clas op locn
31 = addErrLoc locn "" ( \ sty ->
32 ppBesides [ppChar '`', ppr sty op, ppStr "' is not an operation of class `",
33 ppr sty clas, ppStr "'."] )
35 ----------------------------------------------------------------
36 badExportNameErr :: String -> String -> Error
38 badExportNameErr name whats_wrong
40 "Error in the export list" ( \ sty ->
41 ppBesides [ppChar '`', ppStr name, ppStr "' ", ppStr whats_wrong] )
43 ----------------------------------------------------------------
44 badImportNameErr :: String -> String -> String -> SrcLoc -> Error
46 badImportNameErr mod name whats_wrong locn
48 ("Error in an import list for the module `"++mod++"'") ( \ sty ->
49 ppBesides [ppChar '`', ppStr name, ppStr "' ", ppStr whats_wrong] )
51 ----------------------------------------------------------------
52 derivingInIfaceErr :: ProtoName -> [ProtoName] -> SrcLoc -> Error
53 -- GHC doesn't support "deriving" in interfaces
55 derivingInIfaceErr ty deriveds locn
56 = addErrLoc locn "Glasgow Haskell doesn't support `deriving' in interfaces" ( \ sty ->
57 ppBesides [ ppStr "type: ", ppr sty ty,
58 ppStr "; derived: ", interpp'SP sty deriveds ] )
60 ----------------------------------------------------------------
61 derivingNonStdClassErr :: Name -> ProtoName -> SrcLoc -> Error
62 -- if "deriving" specified for a non-standard class
64 derivingNonStdClassErr tycon clas locn
65 = addErrLoc locn "Can't have a derived instance of this class" ( \ sty ->
66 ppBesides [ppStr "type constructor: ", ppr sty tycon,
67 ppStr "; class: ", ppr sty clas] )
69 ----------------------------------------------------------------
70 dupNamesErr :: String -> [(ProtoName,SrcLoc)] -> Error
72 dupNamesErr descriptor ((first_pname,locn1) : dup_things) sty
73 = ppAboves (first_item : map dup_item dup_things)
76 = ppBesides [ ppr PprForUser locn1,
77 ppStr ": multiple declarations of a ", ppStr descriptor, ppStr ": ",
80 dup_item (pname, locn)
81 = ppBesides [ ppr PprForUser locn,
82 ppStr ": here was another declaration of `", ppr sty pname, ppStr "'" ]
84 ----------------------------------------------------------------
85 dupPreludeNameErr :: String -> (ProtoName, SrcLoc) -> Error
87 dupPreludeNameErr descriptor (nm, locn)
88 = addShortErrLocLine locn ( \ sty ->
89 ppBesides [ ppStr "A conflict with a Prelude ", ppStr descriptor,
90 ppStr ": ", ppr sty nm ])
92 ----------------------------------------------------------------
93 dupSigDeclErr :: [RenamedSig] -> Error
94 -- Duplicate signatures in a group; the sigs have locns on them
97 undup_sigs = fst (removeDups cmp_sig sigs)
100 ("more than one "++what_it_is++"\n\thas been given for these variables") ( \ sty ->
101 ppAboves (map (ppr sty) undup_sigs) )
104 = case (head sigs) of
105 Sig _ _ _ loc -> ("type signature",loc)
106 ClassOpSig _ _ _ loc -> ("class-method type signature", loc)
107 SpecSig _ _ _ loc -> ("SPECIALIZE pragma",loc)
108 InlineSig _ _ loc -> ("INLINE pragma",loc)
109 MagicUnfoldingSig _ _ loc -> ("MAGIC_UNFOLDING pragma",loc)
111 cmp_sig a b = get_name a `cmpName` get_name b
113 get_name (Sig n _ _ _) = n
114 get_name (ClassOpSig n _ _ _) = n
115 get_name (SpecSig n _ _ _) = n
116 get_name (InlineSig n _ _) = n
117 get_name (MagicUnfoldingSig n _ _) = n
119 ----------------------------------------------------------------
120 duplicateImportsInInterfaceErr :: String -> [ProtoName] -> Error
121 duplicateImportsInInterfaceErr iface dups
122 = panic "duplicateImportsInInterfaceErr: NOT DONE YET?"
124 ----------------------------------------------------------------
125 inlineInRecursiveBindsErr :: [(Name, SrcLoc)] -> Error
127 inlineInRecursiveBindsErr [(name, locn)]
128 = addShortErrLocLine locn ( \ sty ->
129 ppBesides [ppStr "INLINE pragma for a recursive definition: ",
131 inlineInRecursiveBindsErr names_n_locns
133 ppHang (ppStr "INLINE pragmas for some recursive definitions:")
134 4 (ppAboves [ ppBesides [ppr PprForUser locn, ppStr ": ", ppr sty n]
135 | (n, locn) <- names_n_locns ])
137 ----------------------------------------------------------------
138 --mismatchedPragmasErr :: (Annotations, SrcLoc)
139 -- -> (Annotations, SrcLoc)
142 mismatchedPragmasErr (anns1, _) (anns2, _)
143 = dontAddErrLoc "Mismatched pragmas from interfaces" ( \ sty ->
144 ppSep [ppr sty anns1, ppr sty anns2] )
147 ----------------------------------------------------------------
148 shadowedNameErr :: Name -> SrcLoc -> Error
149 shadowedNameErr shadow locn
150 = addShortErrLocLine locn ( \ sty ->
151 ppBesides [ppStr "more than one value with the same name (shadowing): ",
154 ----------------------------------------------------------------
155 unknownNameErr :: String -> ProtoName -> SrcLoc -> Error
156 unknownNameErr descriptor undef_thing locn
157 = addShortErrLocLine locn ( \ sty ->
158 ppBesides [ppStr "undefined ", ppStr descriptor, ppStr ": ",
159 ppr sty undef_thing] )
161 ----------------------------------------------------------------
162 missingSigErr :: SrcLoc -> ProtoName -> Error
163 -- Top-level definition without a type signature
164 -- (when SigsRequired flag is in use)
165 missingSigErr locn var
166 = addShortErrLocLine locn ( \ sty ->
167 ppBesides [ppStr "a definition but no type signature for `",
171 ----------------------------------------------------------------
172 unknownSigDeclErr :: String -> ProtoName -> SrcLoc -> Error
173 -- Signature/Pragma given for unknown variable
174 unknownSigDeclErr flavor var locn
175 = addShortErrLocLine locn ( \ sty ->
176 ppBesides [ppStr flavor, ppStr " but no definition for `",
180 ----------------------------------------------------------------
181 weirdImportExportConstraintErr :: ProtoName -> IE -> SrcLoc -> Error
183 weirdImportExportConstraintErr thing constraint locn
184 = addShortErrLocLine locn ( \ sty ->
185 ppBesides [ppStr "Illegal import/export constraint on `",
187 ppStr "': ", ppr PprForUser constraint])
189 ----------------------------------------------------------------
190 methodBindErr :: ProtoNameMonoBinds -> SrcLoc -> Error
191 methodBindErr mbind locn
192 = addErrLoc locn "Can't handle multiple methods defined by one pattern binding"
193 (\ sty -> ppr sty mbind)