[project @ 2003-12-30 16:29:17 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnTypes.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnSource]{Main pass of renamer}
5
6 \begin{code}
7 module RnTypes ( rnHsType, rnLHsType, rnContext,
8                  rnHsSigType, rnHsTypeFVs,
9                  rnLPat, rnPat, rnPatsAndThen,          -- Here because it's not part 
10                  rnLit, rnOverLit,                      -- of any mutual recursion      
11                  precParseErr, sectionPrecErr, dupFieldErr, patSigErr, checkTupSize
12   ) where
13
14 import CmdLineOpts      ( DynFlag(Opt_WarnUnusedMatches, Opt_GlasgowExts) )
15
16 import HsSyn
17 import RdrHsSyn         ( extractHsRhoRdrTyVars )
18 import RnHsSyn          ( extractHsTyNames, parrTyCon_name, tupleTyCon_name, 
19                           listTyCon_name
20                         )
21 import RnEnv            ( lookupOccRn, lookupBndrRn, lookupSyntaxName,
22                           lookupLocatedOccRn, lookupLocatedBndrRn,
23                           lookupLocatedGlobalOccRn, bindTyVarsRn, lookupFixityRn,
24                           mapFvRn, warnUnusedMatches,
25                           newIPNameRn, bindPatSigTyVarsFV, bindLocatedLocalsFV )
26 import TcRnMonad
27 import RdrName          ( RdrName, elemLocalRdrEnv )
28 import PrelNames        ( eqClassName, integralClassName, 
29                           negateName, minusName, lengthPName, indexPName,
30                           plusIntegerName, fromIntegerName, timesIntegerName,
31                           ratioDataConName, fromRationalName )
32 import Constants        ( mAX_TUPLE_SIZE )
33 import Name             ( Name )
34 import SrcLoc           ( Located(..), unLoc )
35 import NameSet
36
37 import Literal          ( inIntRange, inCharRange )
38 import BasicTypes       ( compareFixity )
39 import ListSetOps       ( removeDups )
40 import Outputable
41 import Monad            ( when )
42
43 #include "HsVersions.h"
44 \end{code}
45
46 These type renamers are in a separate module, rather than in (say) RnSource,
47 to break several loop.
48
49 %*********************************************************
50 %*                                                      *
51 \subsection{Renaming types}
52 %*                                                      *
53 %*********************************************************
54
55 \begin{code}
56 rnHsTypeFVs :: SDoc -> LHsType RdrName -> RnM (LHsType Name, FreeVars)
57 rnHsTypeFVs doc_str ty 
58   = rnLHsType doc_str ty        `thenM` \ ty' ->
59     returnM (ty', extractHsTyNames ty')
60
61 rnHsSigType :: SDoc -> LHsType RdrName -> RnM (LHsType Name)
62         -- rnHsSigType is used for source-language type signatures,
63         -- which use *implicit* universal quantification.
64 rnHsSigType doc_str ty
65   = rnLHsType (text "In the type signature for" <+> doc_str) ty
66 \end{code}
67
68 rnHsType is here because we call it from loadInstDecl, and I didn't
69 want a gratuitous knot.
70
71 \begin{code}
72 rnLHsType  :: SDoc -> LHsType RdrName -> RnM (LHsType Name)
73 rnLHsType doc = wrapLocM (rnHsType doc)
74
75 rnHsType :: SDoc -> HsType RdrName -> RnM (HsType Name)
76
77 rnHsType doc (HsForAllTy Implicit _ ctxt ty)
78         -- Implicit quantifiction in source code (no kinds on tyvars)
79         -- Given the signature  C => T  we universally quantify 
80         -- over FV(T) \ {in-scope-tyvars} 
81   = getLocalRdrEnv              `thenM` \ name_env ->
82     let
83         mentioned = extractHsRhoRdrTyVars ctxt ty
84
85         -- Don't quantify over type variables that are in scope;
86         -- when GlasgowExts is off, there usually won't be any, except for
87         -- class signatures:
88         --      class C a where { op :: a -> a }
89         forall_tyvars = filter (not . (`elemLocalRdrEnv` name_env) . unLoc) mentioned
90         tyvar_bndrs = [ L loc (UserTyVar v) | (L loc v) <- forall_tyvars ]
91     in
92     rnForAll doc Implicit tyvar_bndrs ctxt ty
93
94 rnHsType doc (HsForAllTy Explicit forall_tyvars ctxt tau)
95         -- Explicit quantification.
96         -- Check that the forall'd tyvars are actually 
97         -- mentioned in the type, and produce a warning if not
98   = let
99         mentioned          = map unLoc (extractHsRhoRdrTyVars ctxt tau)
100         forall_tyvar_names = hsLTyVarLocNames forall_tyvars
101
102         -- Explicitly quantified but not mentioned in ctxt or tau
103         warn_guys = filter ((`notElem` mentioned) . unLoc) forall_tyvar_names
104     in
105     mappM_ (forAllWarn doc tau) warn_guys       `thenM_`
106     rnForAll doc Explicit forall_tyvars ctxt tau
107
108 rnHsType doc (HsTyVar tyvar)
109   = lookupOccRn tyvar           `thenM` \ tyvar' ->
110     returnM (HsTyVar tyvar')
111
112 rnHsType doc (HsOpTy ty1 (L loc op) ty2)
113   = addSrcSpan loc (
114       lookupOccRn op                    `thenM` \ op' ->
115       lookupTyFixityRn (L loc op')      `thenM` \ fix ->
116       rnLHsType doc ty1                 `thenM` \ ty1' ->
117       rnLHsType doc ty2                 `thenM` \ ty2' -> 
118       mkHsOpTyRn (L loc op') fix ty1' ty2'
119    )
120
121 rnHsType doc (HsParTy ty)
122   = rnLHsType doc ty            `thenM` \ ty' ->
123     returnM (HsParTy ty')
124
125 rnHsType doc (HsNumTy i)
126   | i == 1    = returnM (HsNumTy i)
127   | otherwise = addErr err_msg  `thenM_`  returnM (HsNumTy i)
128   where
129     err_msg = ptext SLIT("Only unit numeric type pattern is valid")
130                            
131
132 rnHsType doc (HsFunTy ty1 ty2)
133   = rnLHsType doc ty1   `thenM` \ ty1' ->
134         -- Might find a for-all as the arg of a function type
135     rnLHsType doc ty2   `thenM` \ ty2' ->
136         -- Or as the result.  This happens when reading Prelude.hi
137         -- when we find return :: forall m. Monad m -> forall a. a -> m a
138     returnM (HsFunTy ty1' ty2')
139
140 rnHsType doc (HsListTy ty)
141   = rnLHsType doc ty                            `thenM` \ ty' ->
142     returnM (HsListTy ty')
143
144 rnHsType doc (HsKindSig ty k)
145   = rnLHsType doc ty                            `thenM` \ ty' ->
146     returnM (HsKindSig ty' k)
147
148 rnHsType doc (HsPArrTy ty)
149   = rnLHsType doc ty                            `thenM` \ ty' ->
150     returnM (HsPArrTy ty')
151
152 -- Unboxed tuples are allowed to have poly-typed arguments.  These
153 -- sometimes crop up as a result of CPR worker-wrappering dictionaries.
154 rnHsType doc (HsTupleTy tup_con tys)
155   = mappM (rnLHsType doc) tys           `thenM` \ tys' ->
156     returnM (HsTupleTy tup_con tys')
157
158 rnHsType doc (HsAppTy ty1 ty2)
159   = rnLHsType doc ty1           `thenM` \ ty1' ->
160     rnLHsType doc ty2           `thenM` \ ty2' ->
161     returnM (HsAppTy ty1' ty2')
162
163 rnHsType doc (HsPredTy pred)
164   = rnLPred doc pred    `thenM` \ pred' ->
165     returnM (HsPredTy pred')
166
167 rnLHsTypes doc tys = mappM (rnLHsType doc) tys
168 \end{code}
169
170
171 \begin{code}
172 rnForAll :: SDoc -> HsExplicitForAll -> [LHsTyVarBndr RdrName] -> LHsContext RdrName
173   -> LHsType RdrName -> RnM (HsType Name)
174
175 rnForAll doc exp [] (L _ []) (L _ ty) = rnHsType doc ty
176         -- One reason for this case is that a type like Int#
177         -- starts of as (HsForAllTy Nothing [] Int), in case
178         -- there is some quantification.  Now that we have quantified
179         -- and discovered there are no type variables, it's nicer to turn
180         -- it into plain Int.  If it were Int# instead of Int, we'd actually
181         -- get an error, because the body of a genuine for-all is
182         -- of kind *.
183
184 rnForAll doc exp forall_tyvars ctxt ty
185   = bindTyVarsRn doc forall_tyvars      $ \ new_tyvars ->
186     rnContext doc ctxt                  `thenM` \ new_ctxt ->
187     rnLHsType doc ty                    `thenM` \ new_ty ->
188     returnM (HsForAllTy exp new_tyvars new_ctxt new_ty)
189         -- Retain the same implicit/explicit flag as before
190         -- so that we can later print it correctly
191 \end{code}
192
193
194 %*********************************************************
195 %*                                                      *
196 \subsection{Fixities}
197 %*                                                      *
198 %*********************************************************
199
200 Infix types are read in a *right-associative* way, so that
201         a `op` b `op` c
202 is always read in as
203         a `op` (b `op` c)
204
205 mkHsOpTyRn rearranges where necessary.  The two arguments
206 have already been renamed and rearranged.  It's made rather tiresome
207 by the presence of ->
208
209 \begin{code}
210 lookupTyFixityRn (L loc n)
211   = doptM Opt_GlasgowExts                       `thenM` \ glaExts ->
212     when (not glaExts) 
213         (addSrcSpan loc $ addWarn (infixTyConWarn n))   `thenM_`
214     lookupFixityRn n
215
216 -- Building (ty1 `op1` (ty21 `op2` ty22))
217 mkHsOpTyRn :: Located Name -> Fixity 
218            -> LHsType Name -> LHsType Name 
219            -> RnM (HsType Name)
220
221 mkHsOpTyRn op1 fix1 ty1 ty2@(L loc (HsOpTy ty21 op2 ty22))
222   = lookupTyFixityRn op2        `thenM` \ fix2 ->
223     let
224         (nofix_error, associate_right) = compareFixity fix1 fix2
225     in
226     if nofix_error then
227         addErr (precParseErr (quotes (ppr op1),fix1) 
228                                (quotes (ppr op2),fix2)) `thenM_`
229         returnM (HsOpTy ty1 op1 ty2)
230     else 
231     if not associate_right then
232         -- Rearrange to ((ty1 `op1` ty21) `op2` ty22)
233         mkHsOpTyRn op1 fix1 ty1 ty21            `thenM` \ new_ty ->
234         returnM (HsOpTy (L loc new_ty) op2 ty22)  -- XXX loc is wrong
235     else
236     returnM (HsOpTy ty1 op1 ty2)
237
238 mkHsOpTyRn op fix ty1 ty2                       -- Default case, no rearrangment
239   = returnM (HsOpTy ty1 op ty2)
240 \end{code}
241
242 %*********************************************************
243 %*                                                      *
244 \subsection{Contexts and predicates}
245 %*                                                      *
246 %*********************************************************
247
248 \begin{code}
249 rnContext :: SDoc -> LHsContext RdrName -> RnM (LHsContext Name)
250 rnContext doc = wrapLocM (rnContext' doc)
251
252 rnContext' :: SDoc -> HsContext RdrName -> RnM (HsContext Name)
253 rnContext' doc ctxt = mappM (rnLPred doc) ctxt
254
255 rnLPred :: SDoc -> LHsPred RdrName -> RnM (LHsPred Name)
256 rnLPred doc  = wrapLocM (rnPred doc)
257
258 rnPred doc (HsClassP clas tys)
259   = lookupOccRn clas            `thenM` \ clas_name ->
260     rnLHsTypes doc tys          `thenM` \ tys' ->
261     returnM (HsClassP clas_name tys')
262
263 rnPred doc (HsIParam n ty)
264   = newIPNameRn n               `thenM` \ name ->
265     rnLHsType doc ty            `thenM` \ ty' ->
266     returnM (HsIParam name ty')
267 \end{code}
268
269
270 *********************************************************
271 *                                                       *
272 \subsection{Patterns}
273 *                                                       *
274 *********************************************************
275
276 \begin{code}
277 rnPatsAndThen :: HsMatchContext Name
278               -> Bool
279               -> [LPat RdrName] 
280               -> ([LPat Name] -> RnM (a, FreeVars))
281               -> RnM (a, FreeVars)
282 -- Bring into scope all the binders and type variables
283 -- bound by the patterns; then rename the patterns; then
284 -- do the thing inside.
285 --
286 -- Note that we do a single bindLocalsRn for all the
287 -- matches together, so that we spot the repeated variable in
288 --      f x x = 1
289
290 rnPatsAndThen ctxt repUnused pats thing_inside
291   = bindPatSigTyVarsFV pat_sig_tys      $
292     bindLocatedLocalsFV doc_pat bndrs   $ \ new_bndrs ->
293     rnLPats pats                        `thenM` \ (pats', pat_fvs) ->
294     thing_inside pats'                  `thenM` \ (res, res_fvs) ->
295
296     let
297         unused_binders = filter (not . (`elemNameSet` res_fvs)) new_bndrs
298     in
299     (if repUnused
300      then warnUnusedMatches unused_binders
301      else returnM ())                  `thenM_`
302     returnM (res, res_fvs `plusFV` pat_fvs)
303   where
304     pat_sig_tys = collectSigTysFromPats pats
305     bndrs       = collectLocatedPatsBinders pats
306     doc_pat     = ptext SLIT("In") <+> pprMatchContext ctxt
307
308 rnLPats :: [LPat RdrName] -> RnM ([LPat Name], FreeVars)
309 rnLPats ps = mapFvRn rnLPat ps
310
311 rnLPat :: LPat RdrName -> RnM (LPat Name, FreeVars)
312 rnLPat = wrapLocFstM rnPat
313
314 -- -----------------------------------------------------------------------------
315 -- rnPat
316
317 rnPat :: Pat RdrName -> RnM (Pat Name, FreeVars)
318
319 rnPat (WildPat _) = returnM (WildPat placeHolderType, emptyFVs)
320
321 rnPat (VarPat name)
322   = lookupBndrRn  name                  `thenM` \ vname ->
323     returnM (VarPat vname, emptyFVs)
324
325 rnPat (SigPatIn pat ty)
326   = doptM Opt_GlasgowExts `thenM` \ glaExts ->
327     
328     if glaExts
329     then rnLPat pat             `thenM` \ (pat', fvs1) ->
330          rnHsTypeFVs doc ty     `thenM` \ (ty',  fvs2) ->
331          returnM (SigPatIn pat' ty', fvs1 `plusFV` fvs2)
332
333     else addErr (patSigErr ty)  `thenM_`
334          rnPat (unLoc pat) -- XXX shouldn't throw away the loc
335   where
336     doc = text "In a pattern type-signature"
337     
338 rnPat (LitPat lit) 
339   = rnLit lit   `thenM_` 
340     returnM (LitPat lit, emptyFVs) 
341
342 rnPat (NPatIn lit mb_neg) 
343   = rnOverLit lit                       `thenM` \ (lit', fvs1) ->
344     (case mb_neg of
345         Nothing -> returnM (Nothing, emptyFVs)
346         Just _  -> lookupSyntaxName negateName  `thenM` \ (neg, fvs) ->
347                    returnM (Just neg, fvs)
348     )                                   `thenM` \ (mb_neg', fvs2) ->
349     returnM (NPatIn lit' mb_neg', 
350               fvs1 `plusFV` fvs2 `addOneFV` eqClassName)        
351         -- Needed to find equality on pattern
352
353 rnPat (NPlusKPatIn name lit _)
354   = rnOverLit lit                       `thenM` \ (lit', fvs1) ->
355     lookupLocatedBndrRn name            `thenM` \ name' ->
356     lookupSyntaxName minusName          `thenM` \ (minus, fvs2) ->
357     returnM (NPlusKPatIn name' lit' minus, 
358               fvs1 `plusFV` fvs2 `addOneFV` integralClassName)
359         -- The Report says that n+k patterns must be in Integral
360
361 rnPat (LazyPat pat)
362   = rnLPat pat          `thenM` \ (pat', fvs) ->
363     returnM (LazyPat pat', fvs)
364
365 rnPat (AsPat name pat)
366   = rnLPat pat                  `thenM` \ (pat', fvs) ->
367     lookupLocatedBndrRn name    `thenM` \ vname ->
368     returnM (AsPat vname pat', fvs)
369
370 rnPat (ConPatIn con stuff) = rnConPat con stuff
371
372
373 rnPat (ParPat pat)
374   = rnLPat pat          `thenM` \ (pat', fvs) ->
375     returnM (ParPat pat', fvs)
376
377 rnPat (ListPat pats _)
378   = rnLPats pats                        `thenM` \ (patslist, fvs) ->
379     returnM (ListPat patslist placeHolderType, fvs `addOneFV` listTyCon_name)
380
381 rnPat (PArrPat pats _)
382   = rnLPats pats                        `thenM` \ (patslist, fvs) ->
383     returnM (PArrPat patslist placeHolderType, 
384               fvs `plusFV` implicit_fvs `addOneFV` parrTyCon_name)
385   where
386     implicit_fvs = mkFVs [lengthPName, indexPName]
387
388 rnPat (TuplePat pats boxed)
389   = checkTupSize tup_size       `thenM_`
390     rnLPats pats                        `thenM` \ (patslist, fvs) ->
391     returnM (TuplePat patslist boxed, fvs `addOneFV` tycon_name)
392   where
393     tup_size   = length pats
394     tycon_name = tupleTyCon_name boxed tup_size
395
396 rnPat (TypePat name) =
397     rnHsTypeFVs (text "In a type pattern") name `thenM` \ (name', fvs) ->
398     returnM (TypePat name', fvs)
399
400 -- -----------------------------------------------------------------------------
401 -- rnConPat
402
403 rnConPat con (PrefixCon pats)
404   = lookupLocatedOccRn con      `thenM` \ con' ->
405     rnLPats pats                `thenM` \ (pats', fvs) ->
406     returnM (ConPatIn con' (PrefixCon pats'), fvs `addOneFV` unLoc con')
407
408 rnConPat con (RecCon rpats)
409   = lookupLocatedOccRn con      `thenM` \ con' ->
410     rnRpats rpats               `thenM` \ (rpats', fvs) ->
411     returnM (ConPatIn con' (RecCon rpats'), fvs `addOneFV` unLoc con')
412
413 rnConPat con (InfixCon pat1 pat2)
414   = lookupLocatedOccRn con                      `thenM` \ con' ->
415     rnLPat pat1                                 `thenM` \ (pat1', fvs1) ->
416     rnLPat pat2                                 `thenM` \ (pat2', fvs2) ->
417     lookupFixityRn (unLoc con')                 `thenM` \ fixity ->
418     mkConOpPatRn con' fixity pat1' pat2'        `thenM` \ pat' ->
419     returnM (pat', fvs1 `plusFV` fvs2 `addOneFV` unLoc con')
420
421 -- -----------------------------------------------------------------------------
422 -- rnRpats
423
424 rnRpats :: [(Located RdrName, LPat RdrName)]
425         -> RnM ([(Located Name, LPat Name)], FreeVars)
426 rnRpats rpats
427   = mappM_ field_dup_err dup_fields     `thenM_`
428     mapFvRn rn_rpat rpats               `thenM` \ (rpats', fvs) ->
429     returnM (rpats', fvs)
430   where
431     (_, dup_fields) = removeDups compare [ unLoc f | (f,_) <- rpats ]
432
433     field_dup_err dups = addErr (dupFieldErr "pattern" dups)
434
435     rn_rpat (field, pat)
436       = lookupLocatedGlobalOccRn field  `thenM` \ fieldname ->
437         rnLPat pat                      `thenM` \ (pat', fvs) ->
438         returnM ((fieldname, pat'), fvs `addOneFV` unLoc fieldname)
439
440 -- -----------------------------------------------------------------------------
441 -- mkConOpPatRn
442
443 mkConOpPatRn :: Located Name -> Fixity -> LPat Name -> LPat Name
444              -> RnM (Pat Name)
445
446 mkConOpPatRn op2 fix2 p1@(L loc (ConPatIn op1 (InfixCon p11 p12))) p2
447   = lookupFixityRn (unLoc op1)  `thenM` \ fix1 ->
448     let
449         (nofix_error, associate_right) = compareFixity fix1 fix2
450     in
451     if nofix_error then
452         addErr (precParseErr (ppr_op op1,fix1) (ppr_op op2,fix2))       `thenM_`
453         returnM (ConPatIn op2 (InfixCon p1 p2))
454     else 
455     if associate_right then
456         mkConOpPatRn op2 fix2 p12 p2            `thenM` \ new_p ->
457         returnM (ConPatIn op1 (InfixCon p11 (L loc new_p)))  -- XXX loc right?
458     else
459     returnM (ConPatIn op2 (InfixCon p1 p2))
460
461 mkConOpPatRn op fix p1 p2                       -- Default case, no rearrangment
462   = ASSERT( not_op_pat (unLoc p2) )
463     returnM (ConPatIn op (InfixCon p1 p2))
464
465 not_op_pat (ConPatIn _ (InfixCon _ _)) = False
466 not_op_pat other                       = True
467 \end{code}
468
469
470 %************************************************************************
471 %*                                                                      *
472 \subsubsection{Literals}
473 %*                                                                      *
474 %************************************************************************
475
476 When literals occur we have to make sure
477 that the types and classes they involve
478 are made available.
479
480 \begin{code}
481 rnLit :: HsLit -> RnM ()
482 rnLit (HsChar c) = checkErr (inCharRange c) (bogusCharError c)
483 rnLit other      = returnM ()
484
485 rnOverLit (HsIntegral i _)
486   = lookupSyntaxName fromIntegerName    `thenM` \ (from_integer_name, fvs) ->
487     if inIntRange i then
488         returnM (HsIntegral i from_integer_name, fvs)
489     else let
490         extra_fvs = mkFVs [plusIntegerName, timesIntegerName]
491         -- Big integer literals are built, using + and *, 
492         -- out of small integers (DsUtils.mkIntegerLit)
493         -- [NB: plusInteger, timesInteger aren't rebindable... 
494         --      they are used to construct the argument to fromInteger, 
495         --      which is the rebindable one.]
496     in
497     returnM (HsIntegral i from_integer_name, fvs `plusFV` extra_fvs)
498
499 rnOverLit (HsFractional i _)
500   = lookupSyntaxName fromRationalName           `thenM` \ (from_rat_name, fvs) ->
501     let
502         extra_fvs = mkFVs [ratioDataConName, plusIntegerName, timesIntegerName]
503         -- We have to make sure that the Ratio type is imported with
504         -- its constructor, because literals of type Ratio t are
505         -- built with that constructor.
506         -- The Rational type is needed too, but that will come in
507         -- as part of the type for fromRational.
508         -- The plus/times integer operations may be needed to construct the numerator
509         -- and denominator (see DsUtils.mkIntegerLit)
510     in
511     returnM (HsFractional i from_rat_name, fvs `plusFV` extra_fvs)
512 \end{code}
513
514
515
516 %*********************************************************
517 %*                                                      *
518 \subsection{Errors}
519 %*                                                      *
520 %*********************************************************
521
522 \begin{code}
523 checkTupSize :: Int -> RnM ()
524 checkTupSize tup_size
525   | tup_size <= mAX_TUPLE_SIZE 
526   = returnM ()
527   | otherwise                  
528   = addErr (sep [ptext SLIT("A") <+> int tup_size <> ptext SLIT("-tuple is too large for GHC"),
529                  nest 2 (parens (ptext SLIT("max size is") <+> int mAX_TUPLE_SIZE)),
530                  nest 2 (ptext SLIT("Workaround: use nested tuples or define a data type"))])
531
532 forAllWarn doc ty (L loc tyvar)
533   = ifOptM Opt_WarnUnusedMatches        $
534     addSrcSpan loc $
535     addWarn (sep [ptext SLIT("The universally quantified type variable") <+> quotes (ppr tyvar),
536                    nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))]
537                    $$
538                    doc
539                 )
540
541 bogusCharError c
542   = ptext SLIT("character literal out of range: '\\") <> char c  <> char '\''
543
544 precParseErr op1 op2 
545   = hang (ptext SLIT("precedence parsing error"))
546       4 (hsep [ptext SLIT("cannot mix"), ppr_opfix op1, ptext SLIT("and"), 
547                ppr_opfix op2,
548                ptext SLIT("in the same infix expression")])
549
550 sectionPrecErr op arg_op section
551  = vcat [ptext SLIT("The operator") <+> ppr_opfix op <+> ptext SLIT("of a section"),
552          nest 4 (ptext SLIT("must have lower precedence than the operand") <+> ppr_opfix arg_op),
553          nest 4 (ptext SLIT("in the section:") <+> quotes (ppr section))]
554
555 infixTyConWarn op
556   = ftext FSLIT("Accepting non-standard infix type constructor") <+> quotes (ppr op)
557
558 patSigErr ty
559   =  (ptext SLIT("Illegal signature in pattern:") <+> ppr ty)
560         $$ nest 4 (ptext SLIT("Use -fglasgow-exts to permit it"))
561
562 dupFieldErr str dup
563   = hsep [ptext SLIT("duplicate field name"), 
564           quotes (ppr dup),
565           ptext SLIT("in record"), text str]
566
567 ppr_op op = quotes (ppr op)     -- Here, op can be a Name or a (Var n), where n is a Name
568 ppr_opfix (pp_op, fixity) = pp_op <+> brackets (ppr fixity)
569 \end{code}