Several TH/quasiquote changes
[ghc-hetmet.git] / compiler / rename / RnPat.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnPat]{Renaming of patterns}
5
6 Basically dependency analysis.
7
8 Handles @Match@, @GRHSs@, @HsExpr@, and @Qualifier@ datatypes.  In
9 general, all of these functions return a renamed thing, and a set of
10 free variables.
11
12 \begin{code}
13 module RnPat (-- main entry points
14               rnPat, rnPats, rnBindPat,
15
16               NameMaker, applyNameMaker,     -- a utility for making names:
17               localRecNameMaker, topRecNameMaker,  --   sometimes we want to make local names,
18                                              --   sometimes we want to make top (qualified) names.
19
20               rnHsRecFields1, HsRecFieldContext(..),
21
22               -- Literals
23               rnLit, rnOverLit,     
24
25              -- Pattern Error messages that are also used elsewhere
26              checkTupSize, patSigErr
27              ) where
28
29 -- ENH: thin imports to only what is necessary for patterns
30
31 import {-# SOURCE #-} RnExpr ( rnLExpr )
32 #ifdef GHCI
33 import {-# SOURCE #-} TcSplice ( runQuasiQuotePat )
34 #endif  /* GHCI */
35
36 #include "HsVersions.h"
37
38 import HsSyn            
39 import TcRnMonad
40 import TcHsSyn          ( hsOverLitName )
41 import RnEnv
42 import RnTypes
43 import DynFlags         ( DynFlag(..) )
44 import PrelNames
45 import Constants        ( mAX_TUPLE_SIZE )
46 import Name
47 import NameSet
48 import Module
49 import RdrName
50 import ListSetOps       ( removeDups, minusList )
51 import Outputable
52 import SrcLoc
53 import FastString
54 import Literal          ( inCharRange )
55 import Control.Monad    ( when )
56 \end{code}
57
58
59 %*********************************************************
60 %*                                                      *
61         The CpsRn Monad
62 %*                                                      *
63 %*********************************************************
64
65 Note [CpsRn monad]
66 ~~~~~~~~~~~~~~~~~~
67 The CpsRn monad uses continuation-passing style to support this
68 style of programming:
69
70         do { ...
71            ; ns <- bindNames rs
72            ; ...blah... }
73
74    where rs::[RdrName], ns::[Name]
75
76 The idea is that '...blah...' 
77   a) sees the bindings of ns
78   b) returns the free variables it mentions
79      so that bindNames can report unused ones
80
81 In particular, 
82     mapM rnPatAndThen [p1, p2, p3]
83 has a *left-to-right* scoping: it makes the binders in 
84 p1 scope over p2,p3.
85
86 \begin{code}
87 newtype CpsRn b = CpsRn { unCpsRn :: forall r. (b -> RnM (r, FreeVars))
88                                             -> RnM (r, FreeVars) }
89         -- See Note [CpsRn monad]
90
91 instance Monad CpsRn where
92   return x = CpsRn (\k -> k x)
93   (CpsRn m) >>= mk = CpsRn (\k -> m (\v -> unCpsRn (mk v) k))
94
95 runCps :: CpsRn a -> RnM (a, FreeVars)
96 runCps (CpsRn m) = m (\r -> return (r, emptyFVs))
97
98 liftCps :: RnM a -> CpsRn a
99 liftCps rn_thing = CpsRn (\k -> rn_thing >>= k)
100
101 liftCpsFV :: RnM (a, FreeVars) -> CpsRn a
102 liftCpsFV rn_thing = CpsRn (\k -> do { (v,fvs1) <- rn_thing
103                                      ; (r,fvs2) <- k v
104                                      ; return (r, fvs1 `plusFV` fvs2) })
105
106 wrapSrcSpanCps :: (a -> CpsRn b) -> Located a -> CpsRn (Located b)
107 -- Set the location, and also wrap it around the value returned
108 wrapSrcSpanCps fn (L loc a)
109   = CpsRn (\k -> setSrcSpan loc $ 
110                  unCpsRn (fn a) $ \v -> 
111                  k (L loc v))
112
113 lookupConCps :: Located RdrName -> CpsRn (Located Name)
114 lookupConCps con_rdr 
115   = CpsRn (\k -> do { con_name <- lookupLocatedOccRn con_rdr
116                     ; (r, fvs) <- k con_name
117                     ; return (r, fvs `plusFV` unitFV (unLoc con_name)) })
118 \end{code}
119
120 %*********************************************************
121 %*                                                      *
122         Name makers
123 %*                                                      *
124 %*********************************************************
125
126 Externally abstract type of name makers,
127 which is how you go from a RdrName to a Name
128
129 \begin{code}
130 data NameMaker 
131   = LamMk       -- Lambdas 
132       Bool      -- True <=> report unused bindings
133                 --   (even if True, the warning only comes out 
134                 --    if -fwarn-unused-matches is on)
135
136   | LetMk       -- Let bindings, incl top level
137                 -- Do *not* check for unused bindings
138       (Maybe Module)   -- Just m  => top level of module m
139                        -- Nothing => not top level
140       MiniFixityEnv
141
142 topRecNameMaker :: Module -> MiniFixityEnv -> NameMaker
143 topRecNameMaker mod fix_env = LetMk (Just mod) fix_env
144
145 localRecNameMaker :: MiniFixityEnv -> NameMaker
146 localRecNameMaker fix_env = LetMk Nothing fix_env 
147
148 matchNameMaker :: HsMatchContext a -> NameMaker
149 matchNameMaker ctxt = LamMk report_unused
150   where
151     -- Do not report unused names in interactive contexts
152     -- i.e. when you type 'x <- e' at the GHCi prompt
153     report_unused = case ctxt of
154                       StmtCtxt GhciStmt -> False
155                       _                 -> True
156
157 newName :: NameMaker -> Located RdrName -> CpsRn Name
158 newName (LamMk report_unused) rdr_name
159   = CpsRn (\ thing_inside -> 
160         do { name <- newLocalBndrRn rdr_name
161            ; (res, fvs) <- bindLocalName name (thing_inside name)
162            ; when report_unused $ warnUnusedMatches [name] fvs
163            ; return (res, name `delFV` fvs) })
164
165 newName (LetMk mb_top fix_env) rdr_name
166   = CpsRn (\ thing_inside -> 
167         do { name <- case mb_top of
168                        Nothing  -> newLocalBndrRn rdr_name
169                        Just mod -> newTopSrcBinder mod rdr_name
170            ; bindLocalNamesFV_WithFixities [name] fix_env $
171              thing_inside name })
172                           
173     -- Note: the bindLocalNamesFV_WithFixities is somewhat suspicious 
174     --       because it binds a top-level name as a local name.
175     --       however, this binding seems to work, and it only exists for
176     --       the duration of the patterns and the continuation;
177     --       then the top-level name is added to the global env
178     --       before going on to the RHSes (see RnSource.lhs).
179 \end{code}
180
181
182 %*********************************************************
183 %*                                                      *
184         External entry points
185 %*                                                      *
186 %*********************************************************
187
188 There are various entry points to renaming patterns, depending on
189  (1) whether the names created should be top-level names or local names
190  (2) whether the scope of the names is entirely given in a continuation
191      (e.g., in a case or lambda, but not in a let or at the top-level,
192       because of the way mutually recursive bindings are handled)
193  (3) whether the a type signature in the pattern can bind 
194         lexically-scoped type variables (for unpacking existential 
195         type vars in data constructors)
196  (4) whether we do duplicate and unused variable checking
197  (5) whether there are fixity declarations associated with the names
198      bound by the patterns that need to be brought into scope with them.
199      
200  Rather than burdening the clients of this module with all of these choices,
201  we export the three points in this design space that we actually need:
202
203 \begin{code}
204 -- ----------- Entry point 1: rnPats -------------------
205 -- Binds local names; the scope of the bindings is entirely in the thing_inside
206 --   * allows type sigs to bind type vars
207 --   * local namemaker
208 --   * unused and duplicate checking
209 --   * no fixities
210 rnPats :: HsMatchContext Name -- for error messages
211        -> [LPat RdrName] 
212        -> ([LPat Name] -> RnM (a, FreeVars))
213        -> RnM (a, FreeVars)
214 rnPats ctxt pats thing_inside
215   = do  { envs_before <- getRdrEnvs
216
217           -- (0) bring into scope all of the type variables bound by the patterns
218           -- (1) rename the patterns, bringing into scope all of the term variables
219           -- (2) then do the thing inside.
220         ; bindPatSigTyVarsFV (collectSigTysFromPats pats)     $ 
221           unCpsRn (rnLPatsAndThen (matchNameMaker ctxt) pats) $ \ pats' -> do
222         { -- Check for duplicated and shadowed names 
223                  -- Because we don't bind the vars all at once, we can't
224                  --     check incrementally for duplicates; 
225                  -- Nor can we check incrementally for shadowing, else we'll
226                  --     complain *twice* about duplicates e.g. f (x,x) = ...
227         ; let names = collectPatsBinders pats'
228         ; addErrCtxt doc_pat $ checkDupAndShadowedNames envs_before names
229         ; thing_inside pats' } }
230   where
231     doc_pat = ptext (sLit "In") <+> pprMatchContext ctxt
232
233 rnPat :: HsMatchContext Name -- for error messages
234       -> LPat RdrName 
235       -> (LPat Name -> RnM (a, FreeVars))
236       -> RnM (a, FreeVars)
237 rnPat ctxt pat thing_inside 
238   = rnPats ctxt [pat] (\[pat'] -> thing_inside pat')
239
240 applyNameMaker :: NameMaker -> Located RdrName -> RnM Name
241 applyNameMaker mk rdr = do { (n, _fvs) <- runCps (newName mk rdr); return n }
242
243 -- ----------- Entry point 2: rnBindPat -------------------
244 -- Binds local names; in a recursive scope that involves other bound vars
245 --      e.g let { (x, Just y) = e1; ... } in ...
246 --   * does NOT allows type sig to bind type vars
247 --   * local namemaker
248 --   * no unused and duplicate checking
249 --   * fixities might be coming in
250 rnBindPat :: NameMaker
251           -> LPat RdrName
252           -> RnM (LPat Name, FreeVars)
253    -- Returned FreeVars are the free variables of the pattern,
254    -- of course excluding variables bound by this pattern 
255
256 rnBindPat name_maker pat = runCps (rnLPatAndThen name_maker pat)
257 \end{code}
258
259
260 %*********************************************************
261 %*                                                      *
262         The main event
263 %*                                                      *
264 %*********************************************************
265
266 \begin{code}
267 -- ----------- Entry point 3: rnLPatAndThen -------------------
268 -- General version: parametrized by how you make new names
269
270 rnLPatsAndThen :: NameMaker -> [LPat RdrName] -> CpsRn [LPat Name]
271 rnLPatsAndThen mk = mapM (rnLPatAndThen mk)
272   -- Despite the map, the monad ensures that each pattern binds
273   -- variables that may be mentioned in subsequent patterns in the list
274
275 --------------------
276 -- The workhorse
277 rnLPatAndThen :: NameMaker -> LPat RdrName -> CpsRn (LPat Name)
278 rnLPatAndThen nm lpat = wrapSrcSpanCps (rnPatAndThen nm) lpat
279
280 rnPatAndThen :: NameMaker -> Pat RdrName -> CpsRn (Pat Name)
281 rnPatAndThen _  (WildPat _)   = return (WildPat placeHolderType)
282 rnPatAndThen mk (ParPat pat)  = do { pat' <- rnLPatAndThen mk pat; return (ParPat pat') }
283 rnPatAndThen mk (LazyPat pat) = do { pat' <- rnLPatAndThen mk pat; return (LazyPat pat') }
284 rnPatAndThen mk (BangPat pat) = do { pat' <- rnLPatAndThen mk pat; return (BangPat pat') }
285 rnPatAndThen mk (VarPat rdr)  = do { loc <- liftCps getSrcSpanM
286                                    ; name <- newName mk (L loc rdr)
287                                    ; return (VarPat name) }
288      -- we need to bind pattern variables for view pattern expressions
289      -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple)
290                                      
291 rnPatAndThen mk (SigPatIn pat ty)
292   = do { patsigs <- liftCps (doptM Opt_ScopedTypeVariables)
293        ; if patsigs
294          then do { pat' <- rnLPatAndThen mk pat
295                  ; ty' <- liftCpsFV (rnHsTypeFVs tvdoc ty)
296                  ; return (SigPatIn pat' ty') }
297          else do { liftCps (addErr (patSigErr ty))
298                  ; rnPatAndThen mk (unLoc pat) } }
299   where
300     tvdoc = text "In a pattern type-signature"
301        
302 rnPatAndThen mk (LitPat lit)
303   | HsString s <- lit
304   = do { ovlStr <- liftCps (doptM Opt_OverloadedStrings)
305        ; if ovlStr 
306          then rnPatAndThen mk (mkNPat (mkHsIsString s placeHolderType) Nothing)
307          else normal_lit }
308   | otherwise = normal_lit
309   where
310     normal_lit = do { liftCps (rnLit lit); return (LitPat lit) }
311
312 rnPatAndThen _ (NPat lit mb_neg _eq)
313   = do { lit'    <- liftCpsFV $ rnOverLit lit
314        ; mb_neg' <- liftCpsFV $ case mb_neg of
315                       Nothing -> return (Nothing, emptyFVs)
316                       Just _  -> do { (neg, fvs) <- lookupSyntaxName negateName
317                                     ; return (Just neg, fvs) }
318        ; eq' <- liftCpsFV $ lookupSyntaxName eqName
319        ; return (NPat lit' mb_neg' eq') }
320
321 rnPatAndThen mk (NPlusKPat rdr lit _ _)
322   = do { new_name <- newName mk rdr
323        ; lit'  <- liftCpsFV $ rnOverLit lit
324        ; minus <- liftCpsFV $ lookupSyntaxName minusName
325        ; ge    <- liftCpsFV $ lookupSyntaxName geName
326        ; return (NPlusKPat (L (nameSrcSpan new_name) new_name) lit' ge minus) }
327                 -- The Report says that n+k patterns must be in Integral
328
329 rnPatAndThen mk (AsPat rdr pat)
330   = do { new_name <- newName mk rdr
331        ; pat' <- rnLPatAndThen mk pat
332        ; return (AsPat (L (nameSrcSpan new_name) new_name) pat') }
333
334 rnPatAndThen mk p@(ViewPat expr pat ty)
335   = do { liftCps $ do { vp_flag <- doptM Opt_ViewPatterns
336                       ; checkErr vp_flag (badViewPat p) }
337          -- Because of the way we're arranging the recursive calls,
338          -- this will be in the right context 
339        ; expr' <- liftCpsFV $ rnLExpr expr 
340        ; pat' <- rnLPatAndThen mk pat
341        ; return (ViewPat expr' pat' ty) }
342
343 rnPatAndThen mk (ConPatIn con stuff)
344    -- rnConPatAndThen takes care of reconstructing the pattern
345   = rnConPatAndThen mk con stuff
346
347 rnPatAndThen mk (ListPat pats _)
348   = do { pats' <- rnLPatsAndThen mk pats
349        ; return (ListPat pats' placeHolderType) }
350
351 rnPatAndThen mk (PArrPat pats _)
352   = do { pats' <- rnLPatsAndThen mk pats
353        ; return (PArrPat pats' placeHolderType) }
354
355 rnPatAndThen mk (TuplePat pats boxed _)
356   = do { liftCps $ checkTupSize (length pats)
357        ; pats' <- rnLPatsAndThen mk pats
358        ; return (TuplePat pats' boxed placeHolderType) }
359
360 rnPatAndThen _ (TypePat ty)
361   = do { ty' <- liftCpsFV $ rnHsTypeFVs (text "In a type pattern") ty
362        ; return (TypePat ty') }
363
364 #ifndef GHCI
365 rnPatAndThen _ p@(QuasiQuotePat {}) 
366   = pprPanic "Can't do QuasiQuotePat without GHCi" (ppr p)
367 #else
368 rnPatAndThen mk (QuasiQuotePat qq)
369   = do { pat <- liftCps $ runQuasiQuotePat qq
370        ; L _ pat' <- rnLPatAndThen mk pat
371        ; return pat' }
372 #endif  /* GHCI */
373
374 rnPatAndThen _ pat = pprPanic "rnLPatAndThen" (ppr pat)
375
376
377 --------------------
378 rnConPatAndThen :: NameMaker
379                 -> Located RdrName          -- the constructor
380                 -> HsConPatDetails RdrName 
381                 -> CpsRn (Pat Name)
382
383 rnConPatAndThen mk con (PrefixCon pats)
384   = do  { con' <- lookupConCps con
385         ; pats' <- rnLPatsAndThen mk pats
386         ; return (ConPatIn con' (PrefixCon pats')) }
387
388 rnConPatAndThen mk con (InfixCon pat1 pat2)
389   = do  { con' <- lookupConCps con
390         ; pat1' <- rnLPatAndThen mk pat1
391         ; pat2' <- rnLPatAndThen mk pat2
392         ; fixity <- liftCps $ lookupFixityRn (unLoc con')
393         ; liftCps $ mkConOpPatRn con' fixity pat1' pat2' }
394
395 rnConPatAndThen mk con (RecCon rpats)
396   = do  { con' <- lookupConCps con
397         ; rpats' <- rnHsRecPatsAndThen mk con' rpats
398         ; return (ConPatIn con' (RecCon rpats')) }
399
400 --------------------
401 rnHsRecPatsAndThen :: NameMaker
402                    -> Located Name      -- Constructor
403                    -> HsRecFields RdrName (LPat RdrName)
404                    -> CpsRn (HsRecFields Name (LPat Name))
405 rnHsRecPatsAndThen mk (L _ con) hs_rec_fields@(HsRecFields { rec_dotdot = dd })
406   = do { flds <- liftCpsFV $ rnHsRecFields1 (HsRecFieldPat con) VarPat hs_rec_fields
407        ; flds' <- mapM rn_field (flds `zip` [1..])
408        ; return (HsRecFields { rec_flds = flds', rec_dotdot = dd }) }
409   where 
410     rn_field (fld, n') = do { arg' <- rnLPatAndThen (nested_mk dd mk n') 
411                                                     (hsRecFieldArg fld)
412                             ; return (fld { hsRecFieldArg = arg' }) }
413
414         -- Suppress unused-match reporting for fields introduced by ".."
415     nested_mk Nothing  mk                    _  = mk
416     nested_mk (Just _) mk@(LetMk {})         _  = mk
417     nested_mk (Just n) (LamMk report_unused) n' = LamMk (report_unused && (n' <= n))
418 \end{code}
419
420
421 %************************************************************************
422 %*                                                                      *
423         Record fields
424 %*                                                                      *
425 %************************************************************************
426
427 \begin{code}
428 data HsRecFieldContext 
429   = HsRecFieldCon Name
430   | HsRecFieldPat Name
431   | HsRecFieldUpd
432
433 rnHsRecFields1 
434     :: HsRecFieldContext
435     -> (RdrName -> arg) -- When punning, use this to build a new field
436     -> HsRecFields RdrName (Located arg)
437     -> RnM ([HsRecField Name (Located arg)], FreeVars)
438
439 -- This supprisingly complicated pass
440 --   a) looks up the field name (possibly using disambiguation)
441 --   b) fills in puns and dot-dot stuff
442 -- When we we've finished, we've renamed the LHS, but not the RHS,
443 -- of each x=e binding
444
445 rnHsRecFields1 ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot })
446   = do { pun_ok      <- doptM Opt_RecordPuns
447        ; disambig_ok <- doptM Opt_DisambiguateRecordFields
448        ; parent <- check_disambiguation disambig_ok mb_con
449        ; flds1 <- mapM (rn_fld pun_ok parent) flds
450        ; mapM_ (addErr . dupFieldErr ctxt) dup_flds
451        ; flds2 <- rn_dotdot dotdot mb_con flds1
452        ; return (flds2, mkFVs (getFieldIds flds2)) }
453   where
454     mb_con = case ctxt of
455                 HsRecFieldUpd     -> Nothing
456                 HsRecFieldCon con -> Just con
457                 HsRecFieldPat con -> Just con
458     doc = case mb_con of
459             Nothing  -> ptext (sLit "constructor field name")
460             Just con -> ptext (sLit "field of constructor") <+> quotes (ppr con)
461
462     name_to_arg (L loc n) = L loc (mk_arg (mkRdrUnqual (nameOccName n)))
463
464     rn_fld pun_ok parent (HsRecField { hsRecFieldId = fld
465                                      , hsRecFieldArg = arg
466                                      , hsRecPun = pun })
467       = do { fld' <- wrapLocM (lookupSubBndr parent doc) fld
468            ; arg' <- if pun 
469                      then do { checkErr pun_ok (badPun fld)
470                              ; return (name_to_arg fld') }
471                      else return arg
472            ; return (HsRecField { hsRecFieldId = fld'
473                                 , hsRecFieldArg = arg'
474                                 , hsRecPun = pun }) }
475
476     rn_dotdot Nothing _mb_con flds     -- No ".." at all
477       = return flds
478     rn_dotdot (Just {}) Nothing flds   -- ".." on record update
479       = do { addErr (badDotDot ctxt); return flds }
480     rn_dotdot (Just n) (Just con) flds -- ".." on record con/pat
481       = ASSERT( n == length flds )
482         do { loc <- getSrcSpanM -- Rather approximate
483            ; dd_flag <- doptM Opt_RecordWildCards
484            ; checkErr dd_flag (needFlagDotDot ctxt)
485
486            ; con_fields <- lookupConstructorFields con
487            ; let present_flds = getFieldIds flds
488                  absent_flds  = con_fields `minusList` present_flds
489                  extras = [ HsRecField
490                               { hsRecFieldId = L loc f
491                               , hsRecFieldArg = name_to_arg (L loc f)
492                               , hsRecPun = False }
493                           | f <- absent_flds ]
494
495            ; return (flds ++ extras) }
496
497     check_disambiguation :: Bool -> Maybe Name -> RnM Parent
498     -- When disambiguation is on, return the parent *type constructor*
499     -- That is, the parent of the data constructor.  That's the parent
500     -- to use for looking up record fields.
501     check_disambiguation disambig_ok mb_con
502       | disambig_ok, Just con <- mb_con
503       = do { env <- getGlobalRdrEnv
504            ; return (case lookupGRE_Name env con of
505                        [gre] -> gre_par gre
506                        gres  -> WARN( True, ppr con <+> ppr gres ) NoParent) }
507       | otherwise = return NoParent
508  
509     dup_flds :: [[RdrName]]
510         -- Each list represents a RdrName that occurred more than once
511         -- (the list contains all occurrences)
512         -- Each list in dup_fields is non-empty
513     (_, dup_flds) = removeDups compare (getFieldIds flds)
514
515 getFieldIds :: [HsRecField id arg] -> [id]
516 getFieldIds flds = map (unLoc . hsRecFieldId) flds
517
518 needFlagDotDot :: HsRecFieldContext -> SDoc
519 needFlagDotDot ctxt = vcat [ptext (sLit "Illegal `..' in record") <+> pprRFC ctxt,
520                             ptext (sLit "Use -XRecordWildCards to permit this")]
521
522 badDotDot :: HsRecFieldContext -> SDoc
523 badDotDot ctxt = ptext (sLit "You cannot use `..' in a record") <+> pprRFC ctxt
524
525 badPun :: Located RdrName -> SDoc
526 badPun fld = vcat [ptext (sLit "Illegal use of punning for field") <+> quotes (ppr fld),
527                    ptext (sLit "Use -XNamedFieldPuns to permit this")]
528
529 dupFieldErr :: HsRecFieldContext -> [RdrName] -> SDoc
530 dupFieldErr ctxt dups
531   = hsep [ptext (sLit "duplicate field name"), 
532           quotes (ppr (head dups)),
533           ptext (sLit "in record"), pprRFC ctxt]
534
535 pprRFC :: HsRecFieldContext -> SDoc
536 pprRFC (HsRecFieldCon {}) = ptext (sLit "construction")
537 pprRFC (HsRecFieldPat {}) = ptext (sLit "pattern")
538 pprRFC (HsRecFieldUpd {}) = ptext (sLit "update")
539 \end{code}
540
541
542 %************************************************************************
543 %*                                                                      *
544 \subsubsection{Literals}
545 %*                                                                      *
546 %************************************************************************
547
548 When literals occur we have to make sure
549 that the types and classes they involve
550 are made available.
551
552 \begin{code}
553 rnLit :: HsLit -> RnM ()
554 rnLit (HsChar c) = checkErr (inCharRange c) (bogusCharError c)
555 rnLit _ = return ()
556
557 rnOverLit :: HsOverLit t -> RnM (HsOverLit Name, FreeVars)
558 rnOverLit lit@(OverLit {ol_val=val})
559   = do  { let std_name = hsOverLitName val
560         ; (from_thing_name, fvs) <- lookupSyntaxName std_name
561         ; let rebindable = case from_thing_name of
562                                 HsVar v -> v /= std_name
563                                 _       -> panic "rnOverLit"
564         ; return (lit { ol_witness = from_thing_name
565                       , ol_rebindable = rebindable }, fvs) }
566 \end{code}
567
568 %************************************************************************
569 %*                                                                      *
570 \subsubsection{Errors}
571 %*                                                                      *
572 %************************************************************************
573
574 \begin{code}
575 checkTupSize :: Int -> RnM ()
576 checkTupSize tup_size
577   | tup_size <= mAX_TUPLE_SIZE 
578   = return ()
579   | otherwise                  
580   = addErr (sep [ptext (sLit "A") <+> int tup_size <> ptext (sLit "-tuple is too large for GHC"),
581                  nest 2 (parens (ptext (sLit "max size is") <+> int mAX_TUPLE_SIZE)),
582                  nest 2 (ptext (sLit "Workaround: use nested tuples or define a data type"))])
583
584 patSigErr :: Outputable a => a -> SDoc
585 patSigErr ty
586   =  (ptext (sLit "Illegal signature in pattern:") <+> ppr ty)
587         $$ nest 4 (ptext (sLit "Use -XScopedTypeVariables to permit it"))
588
589 bogusCharError :: Char -> SDoc
590 bogusCharError c
591   = ptext (sLit "character literal out of range: '\\") <> char c  <> char '\''
592
593 badViewPat :: Pat RdrName -> SDoc
594 badViewPat pat = vcat [ptext (sLit "Illegal view pattern: ") <+> ppr pat,
595                        ptext (sLit "Use -XViewPatterns to enable view patterns")]
596 \end{code}