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