[project @ 2004-10-11 16:16:20 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcExpr.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[TcExpr]{Typecheck an expression}
5
6 \begin{code}
7 module TcExpr ( tcCheckSigma, tcCheckRho, tcInferRho, tcMonoExpr ) where
8
9 #include "HsVersions.h"
10
11 #ifdef GHCI     /* Only if bootstrapped */
12 import {-# SOURCE #-}   TcSplice( tcSpliceExpr, tcBracket )
13 import Id               ( Id )
14 import TcType           ( isTauTy )
15 import TcEnv            ( checkWellStaged )
16 import HsSyn            ( nlHsApp )
17 import qualified DsMeta
18 #endif
19
20 import HsSyn            ( HsExpr(..), LHsExpr, HsLit(..), ArithSeqInfo(..), recBindFields,
21                           HsMatchContext(..), HsRecordBinds, mkHsApp, nlHsVar )
22 import TcHsSyn          ( hsLitType, (<$>) )
23 import TcRnMonad
24 import TcUnify          ( Expected(..), tcInfer, zapExpectedType, zapExpectedTo, tcSubExp, tcGen,
25                           unifyFunTys, zapToListTy, zapToTyConApp )
26 import BasicTypes       ( isMarkedStrict )
27 import Inst             ( InstOrigin(..), 
28                           newOverloadedLit, newMethodFromName, newIPDict,
29                           newDicts, newMethodWithGivenTy, tcInstStupidTheta, tcInstCall )
30 import TcBinds          ( tcBindsAndThen )
31 import TcEnv            ( tcLookup, tcLookupId, checkProcLevel,
32                           tcLookupDataCon, tcLookupGlobalId
33                         )
34 import TcArrows         ( tcProc )
35 import TcMatches        ( tcMatchesCase, tcMatchLambda, tcDoStmts, tcThingWithSig, TcMatchCtxt(..) )
36 import TcHsType         ( tcHsSigType, UserTypeCtxt(..) )
37 import TcPat            ( badFieldCon )
38 import TcMType          ( tcInstTyVars, tcInstType, newTyFlexiVarTy, zonkTcType, readMetaTyVar )
39 import TcType           ( Type, TcTyVar, TcType, TcSigmaType, TcRhoType, MetaDetails(..),
40                           tcSplitFunTys, tcSplitTyConApp, mkTyVarTys,
41                           isSigmaTy, mkFunTy, mkTyConApp, tyVarsOfTypes, isLinearPred,
42                           tcSplitSigmaTy, tidyOpenType
43                         )
44 import Kind             ( openTypeKind, liftedTypeKind, argTypeKind )
45
46 import Id               ( idType, recordSelectorFieldLabel, isRecordSelector )
47 import DataCon          ( DataCon, dataConFieldLabels, dataConStrictMarks, dataConWrapId )
48 import Name             ( Name )
49 import TyCon            ( TyCon, FieldLabel, tyConTyVars, tyConStupidTheta, 
50                           tyConDataCons, tyConFields )
51 import Type             ( zipTopTvSubst, mkTopTvSubst, substTheta, substTy )
52 import VarSet           ( emptyVarSet, elemVarSet )
53 import TysWiredIn       ( boolTy, parrTyCon, tupleTyCon )
54 import PrelNames        ( enumFromName, enumFromThenName, 
55                           enumFromToName, enumFromThenToName,
56                           enumFromToPName, enumFromThenToPName
57                         )
58 import ListSetOps       ( minusList )
59 import CmdLineOpts
60 import HscTypes         ( TyThing(..) )
61 import SrcLoc           ( Located(..), unLoc, getLoc )
62 import Util
63 import Maybes           ( catMaybes )
64 import Outputable
65 import FastString
66
67 #ifdef DEBUG
68 import TyCon            ( isAlgTyCon )
69 #endif
70 \end{code}
71
72 %************************************************************************
73 %*                                                                      *
74 \subsection{Main wrappers}
75 %*                                                                      *
76 %************************************************************************
77
78 \begin{code}
79 -- tcCheckSigma does type *checking*; it's passed the expected type of the result
80 tcCheckSigma :: LHsExpr Name            -- Expession to type check
81              -> TcSigmaType             -- Expected type (could be a polytpye)
82              -> TcM (LHsExpr TcId)      -- Generalised expr with expected type
83
84 tcCheckSigma expr expected_ty 
85   = traceTc (text "tcExpr" <+> (ppr expected_ty $$ ppr expr)) `thenM_`
86     tc_expr' expr expected_ty
87
88 tc_expr' expr sigma_ty
89   | isSigmaTy sigma_ty
90   = tcGen sigma_ty emptyVarSet (
91         \ rho_ty -> tcCheckRho expr rho_ty
92     )                           `thenM` \ (gen_fn, expr') ->
93     returnM (L (getLoc expr') (gen_fn <$> unLoc expr'))
94
95 tc_expr' expr rho_ty    -- Monomorphic case
96   = tcCheckRho expr rho_ty
97 \end{code}
98
99 Typecheck expression which in most cases will be an Id.
100 The expression can return a higher-ranked type, such as
101         (forall a. a->a) -> Int
102 so we must create a hole to pass in as the expected tyvar.
103
104 \begin{code}
105 tcCheckRho :: LHsExpr Name -> TcRhoType -> TcM (LHsExpr TcId)
106 tcCheckRho expr rho_ty = tcMonoExpr expr (Check rho_ty)
107
108 tcInferRho :: LHsExpr Name -> TcM (LHsExpr TcId, TcRhoType)
109 tcInferRho (L loc (HsVar name)) = setSrcSpan loc $ do 
110                                   { (e,_,ty) <- tcId name; return (L loc e, ty)}
111 tcInferRho expr                 = tcInfer (tcMonoExpr expr)
112 \end{code}
113
114
115
116 %************************************************************************
117 %*                                                                      *
118 \subsection{The TAUT rules for variables}TcExpr
119 %*                                                                      *
120 %************************************************************************
121
122 \begin{code}
123 tcMonoExpr :: LHsExpr Name              -- Expession to type check
124            -> Expected TcRhoType        -- Expected type (could be a type variable)
125                                         -- Definitely no foralls at the top
126                                         -- Can be a 'hole'.
127            -> TcM (LHsExpr TcId)
128
129 tcMonoExpr (L loc expr) res_ty
130   = setSrcSpan loc (do { expr' <- tc_expr expr res_ty
131                        ; return (L loc expr') })
132
133 tc_expr :: HsExpr Name -> Expected TcRhoType -> TcM (HsExpr TcId)
134 tc_expr (HsVar name) res_ty
135   = do  { (expr', _, id_ty) <- tcId name
136         ; co_fn <- tcSubExp res_ty id_ty
137         ; returnM (co_fn <$> expr') }
138
139 tc_expr (HsIPVar ip) res_ty
140   =     -- Implicit parameters must have a *tau-type* not a 
141         -- type scheme.  We enforce this by creating a fresh
142         -- type variable as its type.  (Because res_ty may not
143         -- be a tau-type.)
144     newTyFlexiVarTy argTypeKind         `thenM` \ ip_ty ->
145         -- argTypeKind: it can't be an unboxed tuple
146     newIPDict (IPOccOrigin ip) ip ip_ty `thenM` \ (ip', inst) ->
147     extendLIE inst                      `thenM_`
148     tcSubExp res_ty ip_ty               `thenM` \ co_fn ->
149     returnM (co_fn <$> HsIPVar ip')
150 \end{code}
151
152
153 %************************************************************************
154 %*                                                                      *
155 \subsection{Expressions type signatures}
156 %*                                                                      *
157 %************************************************************************
158
159 \begin{code}
160 tc_expr in_expr@(ExprWithTySig expr poly_ty) res_ty
161  = addErrCtxt (exprCtxt in_expr)                        $
162    tcHsSigType ExprSigCtxt poly_ty                      `thenM` \ sig_tc_ty ->
163    tcThingWithSig sig_tc_ty (tcCheckRho expr) res_ty    `thenM` \ (co_fn, expr') ->
164    returnM (co_fn <$> ExprWithTySigOut expr' poly_ty)
165
166 tc_expr (HsType ty) res_ty
167   = failWithTc (text "Can't handle type argument:" <+> ppr ty)
168         -- This is the syntax for type applications that I was planning
169         -- but there are difficulties (e.g. what order for type args)
170         -- so it's not enabled yet.
171         -- Can't eliminate it altogether from the parser, because the
172         -- same parser parses *patterns*.
173 \end{code}
174
175
176 %************************************************************************
177 %*                                                                      *
178 \subsection{Other expression forms}
179 %*                                                                      *
180 %************************************************************************
181
182 \begin{code}
183 tc_expr (HsPar expr)    res_ty  = tcMonoExpr expr res_ty        `thenM` \ expr' -> 
184                                   returnM (HsPar expr')
185 tc_expr (HsSCC lbl expr) res_ty = tcMonoExpr expr res_ty        `thenM` \ expr' ->
186                                   returnM (HsSCC lbl expr')
187 tc_expr (HsCoreAnn lbl expr) res_ty = tcMonoExpr expr res_ty `thenM` \ expr' ->  -- hdaume: core annotation
188                                          returnM (HsCoreAnn lbl expr')
189
190 tc_expr (HsLit lit) res_ty  = tcLit lit res_ty
191
192 tc_expr (HsOverLit lit) res_ty  
193   = zapExpectedType res_ty liftedTypeKind               `thenM` \ res_ty' ->
194     newOverloadedLit (LiteralOrigin lit) lit res_ty'    `thenM` \ lit_expr ->
195     returnM (unLoc lit_expr)    -- ToDo: nasty unLoc
196
197 tc_expr (NegApp expr neg_name) res_ty
198   = tc_expr (HsApp (nlHsVar neg_name) expr) res_ty
199         -- ToDo: use tcSyntaxName
200
201 tc_expr (HsLam match) res_ty
202   = tcMatchLambda match res_ty          `thenM` \ match' ->
203     returnM (HsLam match')
204
205 tc_expr (HsApp e1 e2) res_ty 
206   = tcApp e1 [e2] res_ty
207 \end{code}
208
209 Note that the operators in sections are expected to be binary, and
210 a type error will occur if they aren't.
211
212 \begin{code}
213 -- Left sections, equivalent to
214 --      \ x -> e op x,
215 -- or
216 --      \ x -> op e x,
217 -- or just
218 --      op e
219
220 tc_expr in_expr@(SectionL arg1 op) res_ty
221   = tcInferRho op                               `thenM` \ (op', op_ty) ->
222     unifyFunTys 2 op_ty {- two args -}          `thenM` \ ([arg1_ty, arg2_ty], op_res_ty) ->
223     tcArg op (arg1, arg1_ty, 1)                 `thenM` \ arg1' ->
224     addErrCtxt (exprCtxt in_expr)               $
225     tcSubExp res_ty (mkFunTy arg2_ty op_res_ty) `thenM` \ co_fn ->
226     returnM (co_fn <$> SectionL arg1' op')
227
228 -- Right sections, equivalent to \ x -> x op expr, or
229 --      \ x -> op x expr
230
231 tc_expr in_expr@(SectionR op arg2) res_ty
232   = tcInferRho op                               `thenM` \ (op', op_ty) ->
233     unifyFunTys 2 op_ty {- two args -}          `thenM` \ ([arg1_ty, arg2_ty], op_res_ty) ->
234     tcArg op (arg2, arg2_ty, 2)                 `thenM` \ arg2' ->
235     addErrCtxt (exprCtxt in_expr)               $
236     tcSubExp res_ty (mkFunTy arg1_ty op_res_ty) `thenM` \ co_fn ->
237     returnM (co_fn <$> SectionR op' arg2')
238
239 -- equivalent to (op e1) e2:
240
241 tc_expr in_expr@(OpApp arg1 op fix arg2) res_ty
242   = tcInferRho op                               `thenM` \ (op', op_ty) ->
243     unifyFunTys 2 op_ty {- two args -}          `thenM` \ ([arg1_ty, arg2_ty], op_res_ty) ->
244     tcArg op (arg1, arg1_ty, 1)                 `thenM` \ arg1' ->
245     tcArg op (arg2, arg2_ty, 2)                 `thenM` \ arg2' ->
246     addErrCtxt (exprCtxt in_expr)               $
247     tcSubExp res_ty op_res_ty                   `thenM` \ co_fn ->
248     returnM (OpApp arg1' op' fix arg2')
249 \end{code}
250
251 \begin{code}
252 tc_expr (HsLet binds (L loc expr)) res_ty
253   = tcBindsAndThen
254         glue
255         binds                   -- Bindings to check
256         (setSrcSpan loc $ tc_expr expr res_ty)
257   where
258     glue bind expr = HsLet [bind] (L loc expr)
259
260 tc_expr in_expr@(HsCase scrut matches) exp_ty
261   =     -- We used to typecheck the case alternatives first.
262         -- The case patterns tend to give good type info to use
263         -- when typechecking the scrutinee.  For example
264         --      case (map f) of
265         --        (x:xs) -> ...
266         -- will report that map is applied to too few arguments
267         --
268         -- But now, in the GADT world, we need to typecheck the scrutinee
269         -- first, to get type info that may be refined in the case alternatives
270     addErrCtxt (caseScrutCtxt scrut)
271                (tcInferRho scrut)       `thenM`    \ (scrut', scrut_ty) ->
272
273     addErrCtxt (caseCtxt in_expr)                       $
274     tcMatchesCase match_ctxt scrut_ty matches exp_ty    `thenM` \ matches' ->
275     returnM (HsCase scrut' matches') 
276  where
277     match_ctxt = MC { mc_what = CaseAlt,
278                       mc_body = tcMonoExpr }
279
280 tc_expr (HsIf pred b1 b2) res_ty
281   = addErrCtxt (predCtxt pred) (
282     tcCheckRho pred boolTy      )       `thenM`    \ pred' ->
283
284     zapExpectedType res_ty openTypeKind `thenM`    \ res_ty' ->
285         -- C.f. the call to zapToType in TcMatches.tcMatches
286
287     tcCheckRho b1 res_ty'               `thenM`    \ b1' ->
288     tcCheckRho b2 res_ty'               `thenM`    \ b2' ->
289     returnM (HsIf pred' b1' b2')
290
291 tc_expr (HsDo do_or_lc stmts method_names _) res_ty
292   = zapExpectedType res_ty liftedTypeKind               `thenM` \ res_ty' ->
293         -- All comprehensions yield a monotype of kind *
294     tcDoStmts do_or_lc stmts method_names res_ty'       `thenM` \ (stmts', methods') ->
295     returnM (HsDo do_or_lc stmts' methods' res_ty')
296
297 tc_expr in_expr@(ExplicitList _ exprs) res_ty   -- Non-empty list
298   = zapToListTy res_ty                `thenM` \ elt_ty ->  
299     mappM (tc_elt elt_ty) exprs       `thenM` \ exprs' ->
300     returnM (ExplicitList elt_ty exprs')
301   where
302     tc_elt elt_ty expr
303       = addErrCtxt (listCtxt expr) $
304         tcCheckRho expr elt_ty
305
306 tc_expr in_expr@(ExplicitPArr _ exprs) res_ty   -- maybe empty
307   = do  { [elt_ty] <- zapToTyConApp parrTyCon res_ty
308         ; exprs' <- mappM (tc_elt elt_ty) exprs 
309         ; return (ExplicitPArr elt_ty exprs') }
310   where
311     tc_elt elt_ty expr
312       = addErrCtxt (parrCtxt expr) (tcCheckRho expr elt_ty)
313
314 tc_expr (ExplicitTuple exprs boxity) res_ty
315   = do  { arg_tys <- zapToTyConApp (tupleTyCon boxity (length exprs)) res_ty
316         ; exprs' <-  tcCheckRhos exprs arg_tys
317         ; return (ExplicitTuple exprs' boxity) }
318
319 tc_expr (HsProc pat cmd) res_ty
320   = tcProc pat cmd res_ty                       `thenM` \ (pat', cmd') ->
321     returnM (HsProc pat' cmd')
322
323 tc_expr e@(HsArrApp _ _ _ _ _) _
324   = failWithTc (vcat [ptext SLIT("The arrow command"), nest 2 (ppr e), 
325                       ptext SLIT("was found where an expression was expected")])
326
327 tc_expr e@(HsArrForm _ _ _) _
328   = failWithTc (vcat [ptext SLIT("The arrow command"), nest 2 (ppr e), 
329                       ptext SLIT("was found where an expression was expected")])
330 \end{code}
331
332 %************************************************************************
333 %*                                                                      *
334                 Record construction and update
335 %*                                                                      *
336 %************************************************************************
337
338 \begin{code}
339 tc_expr expr@(RecordCon con@(L loc con_name) rbinds) res_ty
340   = addErrCtxt (recordConCtxt expr)             $
341     addLocM tcId con                    `thenM` \ (con_expr, _, con_tau) ->
342     let
343         (_, record_ty)   = tcSplitFunTys con_tau
344         (tycon, ty_args) = tcSplitTyConApp record_ty
345     in
346     ASSERT( isAlgTyCon tycon )
347     zapExpectedTo res_ty record_ty      `thenM_`
348
349         -- Check that the record bindings match the constructor
350         -- con_name is syntactically constrained to be a data constructor
351     tcLookupDataCon con_name            `thenM` \ data_con ->
352     let
353         bad_fields = badFields rbinds data_con
354     in
355     if notNull bad_fields then
356         mappM (addErrTc . badFieldCon data_con) bad_fields      `thenM_`
357         failM   -- Fail now, because tcRecordBinds will crash on a bad field
358     else
359
360         -- Typecheck the record bindings
361     tcRecordBinds tycon ty_args rbinds          `thenM` \ rbinds' ->
362     
363         -- Check for missing fields
364     checkMissingFields data_con rbinds          `thenM_` 
365
366     getSrcSpanM                                 `thenM` \ loc ->
367     returnM (RecordConOut data_con (L loc con_expr) rbinds')
368
369 -- The main complication with RecordUpd is that we need to explicitly
370 -- handle the *non-updated* fields.  Consider:
371 --
372 --      data T a b = MkT1 { fa :: a, fb :: b }
373 --                 | MkT2 { fa :: a, fc :: Int -> Int }
374 --                 | MkT3 { fd :: a }
375 --      
376 --      upd :: T a b -> c -> T a c
377 --      upd t x = t { fb = x}
378 --
379 -- The type signature on upd is correct (i.e. the result should not be (T a b))
380 -- because upd should be equivalent to:
381 --
382 --      upd t x = case t of 
383 --                      MkT1 p q -> MkT1 p x
384 --                      MkT2 a b -> MkT2 p b
385 --                      MkT3 d   -> error ...
386 --
387 -- So we need to give a completely fresh type to the result record,
388 -- and then constrain it by the fields that are *not* updated ("p" above).
389 --
390 -- Note that because MkT3 doesn't contain all the fields being updated,
391 -- its RHS is simply an error, so it doesn't impose any type constraints
392 --
393 -- All this is done in STEP 4 below.
394
395 tc_expr expr@(RecordUpd record_expr rbinds) res_ty
396   = addErrCtxt (recordUpdCtxt   expr)           $
397
398         -- STEP 0
399         -- Check that the field names are really field names
400     ASSERT( notNull rbinds )
401     let 
402         field_names = map fst rbinds
403     in
404     mappM (tcLookupGlobalId.unLoc) field_names  `thenM` \ sel_ids ->
405         -- The renamer has already checked that they
406         -- are all in scope
407     let
408         bad_guys = [ setSrcSpan loc $ addErrTc (notSelector field_name) 
409                    | (L loc field_name, sel_id) <- field_names `zip` sel_ids,
410                      not (isRecordSelector sel_id)      -- Excludes class ops
411                    ]
412     in
413     checkM (null bad_guys) (sequenceM bad_guys `thenM_` failM)  `thenM_`
414     
415         -- STEP 1
416         -- Figure out the tycon and data cons from the first field name
417     let
418                 -- It's OK to use the non-tc splitters here (for a selector)
419         sel_id : _   = sel_ids
420         (tycon, _)   = recordSelectorFieldLabel sel_id  -- We've failed already if
421         data_cons    = tyConDataCons tycon              -- it's not a field label
422         tycon_tyvars = tyConTyVars tycon                -- The data cons use the same type vars
423     in
424     tcInstTyVars tycon_tyvars           `thenM` \ (_, result_inst_tys, inst_env) ->
425
426         -- STEP 2
427         -- Check that at least one constructor has all the named fields
428         -- i.e. has an empty set of bad fields returned by badFields
429     checkTc (any (null . badFields rbinds) data_cons)
430             (badFieldsUpd rbinds)       `thenM_`
431
432         -- STEP 3
433         -- Typecheck the update bindings.
434         -- (Do this after checking for bad fields in case there's a field that
435         --  doesn't match the constructor.)
436     let
437         result_record_ty = mkTyConApp tycon result_inst_tys
438     in
439     zapExpectedTo res_ty result_record_ty       `thenM_`
440     tcRecordBinds tycon result_inst_tys rbinds  `thenM` \ rbinds' ->
441
442         -- STEP 4
443         -- Use the un-updated fields to find a vector of booleans saying
444         -- which type arguments must be the same in updatee and result.
445         --
446         -- WARNING: this code assumes that all data_cons in a common tycon
447         -- have FieldLabels abstracted over the same tyvars.
448     let
449         upd_field_lbls      = recBindFields rbinds
450         con_field_lbls_s    = map dataConFieldLabels data_cons
451
452                 -- A constructor is only relevant to this process if
453                 -- it contains all the fields that are being updated
454         relevant_field_lbls_s      = filter is_relevant con_field_lbls_s
455         is_relevant con_field_lbls = all (`elem` con_field_lbls) upd_field_lbls
456
457         non_upd_field_lbls  = concat relevant_field_lbls_s `minusList` upd_field_lbls
458         common_tyvars       = tyVarsOfTypes [ty | (fld,ty,_) <- tyConFields tycon,
459                                                   fld `elem` non_upd_field_lbls]
460
461         mk_inst_ty tyvar result_inst_ty 
462           | tyvar `elemVarSet` common_tyvars = returnM result_inst_ty   -- Same as result type
463 -- gaw 2004 FIX?
464           | otherwise                        = newTyFlexiVarTy liftedTypeKind   -- Fresh type
465     in
466     zipWithM mk_inst_ty tycon_tyvars result_inst_tys    `thenM` \ inst_tys ->
467
468         -- STEP 5
469         -- Typecheck the expression to be updated
470     let
471         record_ty = mkTyConApp tycon inst_tys
472     in
473     tcCheckRho record_expr record_ty            `thenM` \ record_expr' ->
474
475         -- STEP 6
476         -- Figure out the LIE we need.  We have to generate some 
477         -- dictionaries for the data type context, since we are going to
478         -- do pattern matching over the data cons.
479         --
480         -- What dictionaries do we need?  
481         -- We just take the context of the type constructor
482     let
483         theta' = substTheta inst_env (tyConStupidTheta tycon)
484     in
485     newDicts RecordUpdOrigin theta'     `thenM` \ dicts ->
486     extendLIEs dicts                    `thenM_`
487
488         -- Phew!
489     returnM (RecordUpdOut record_expr' record_ty result_record_ty rbinds') 
490 \end{code}
491
492
493 %************************************************************************
494 %*                                                                      *
495         Arithmetic sequences                    e.g. [a,b..]
496         and their parallel-array counterparts   e.g. [: a,b.. :]
497                 
498 %*                                                                      *
499 %************************************************************************
500
501 \begin{code}
502 tc_expr (ArithSeqIn seq@(From expr)) res_ty
503   = zapToListTy res_ty                          `thenM` \ elt_ty ->  
504     tcCheckRho expr elt_ty                      `thenM` \ expr' ->
505
506     newMethodFromName (ArithSeqOrigin seq) 
507                       elt_ty enumFromName       `thenM` \ enum_from ->
508
509     returnM (ArithSeqOut (nlHsVar enum_from) (From expr'))
510
511 tc_expr in_expr@(ArithSeqIn seq@(FromThen expr1 expr2)) res_ty
512   = addErrCtxt (arithSeqCtxt in_expr) $ 
513     zapToListTy  res_ty                                 `thenM`    \ elt_ty ->  
514     tcCheckRho expr1 elt_ty                             `thenM`    \ expr1' ->
515     tcCheckRho expr2 elt_ty                             `thenM`    \ expr2' ->
516     newMethodFromName (ArithSeqOrigin seq) 
517                       elt_ty enumFromThenName           `thenM` \ enum_from_then ->
518
519     returnM (ArithSeqOut (nlHsVar enum_from_then) (FromThen expr1' expr2'))
520
521
522 tc_expr in_expr@(ArithSeqIn seq@(FromTo expr1 expr2)) res_ty
523   = addErrCtxt (arithSeqCtxt in_expr) $
524     zapToListTy  res_ty                                 `thenM`    \ elt_ty ->  
525     tcCheckRho expr1 elt_ty                             `thenM`    \ expr1' ->
526     tcCheckRho expr2 elt_ty                             `thenM`    \ expr2' ->
527     newMethodFromName (ArithSeqOrigin seq) 
528                       elt_ty enumFromToName             `thenM` \ enum_from_to ->
529
530     returnM (ArithSeqOut (nlHsVar enum_from_to) (FromTo expr1' expr2'))
531
532 tc_expr in_expr@(ArithSeqIn seq@(FromThenTo expr1 expr2 expr3)) res_ty
533   = addErrCtxt  (arithSeqCtxt in_expr) $
534     zapToListTy  res_ty                                 `thenM`    \ elt_ty ->  
535     tcCheckRho expr1 elt_ty                             `thenM`    \ expr1' ->
536     tcCheckRho expr2 elt_ty                             `thenM`    \ expr2' ->
537     tcCheckRho expr3 elt_ty                             `thenM`    \ expr3' ->
538     newMethodFromName (ArithSeqOrigin seq) 
539                       elt_ty enumFromThenToName         `thenM` \ eft ->
540
541     returnM (ArithSeqOut (nlHsVar eft) (FromThenTo expr1' expr2' expr3'))
542
543 tc_expr in_expr@(PArrSeqIn seq@(FromTo expr1 expr2)) res_ty
544   = addErrCtxt (parrSeqCtxt in_expr) $
545     zapToTyConApp parrTyCon res_ty                      `thenM`    \ [elt_ty] ->  
546     tcCheckRho expr1 elt_ty                             `thenM`    \ expr1' ->
547     tcCheckRho expr2 elt_ty                             `thenM`    \ expr2' ->
548     newMethodFromName (PArrSeqOrigin seq) 
549                       elt_ty enumFromToPName            `thenM` \ enum_from_to ->
550
551     returnM (PArrSeqOut (nlHsVar enum_from_to) (FromTo expr1' expr2'))
552
553 tc_expr in_expr@(PArrSeqIn seq@(FromThenTo expr1 expr2 expr3)) res_ty
554   = addErrCtxt  (parrSeqCtxt in_expr) $
555     zapToTyConApp parrTyCon res_ty                      `thenM`    \ [elt_ty] ->  
556     tcCheckRho expr1 elt_ty                             `thenM`    \ expr1' ->
557     tcCheckRho expr2 elt_ty                             `thenM`    \ expr2' ->
558     tcCheckRho expr3 elt_ty                             `thenM`    \ expr3' ->
559     newMethodFromName (PArrSeqOrigin seq)
560                       elt_ty enumFromThenToPName        `thenM` \ eft ->
561
562     returnM (PArrSeqOut (nlHsVar eft) (FromThenTo expr1' expr2' expr3'))
563
564 tc_expr (PArrSeqIn _) _ 
565   = panic "TcExpr.tcMonoExpr: Infinite parallel array!"
566     -- the parser shouldn't have generated it and the renamer shouldn't have
567     -- let it through
568 \end{code}
569
570
571 %************************************************************************
572 %*                                                                      *
573                 Template Haskell
574 %*                                                                      *
575 %************************************************************************
576
577 \begin{code}
578 #ifdef GHCI     /* Only if bootstrapped */
579         -- Rename excludes these cases otherwise
580 tc_expr (HsSpliceE splice) res_ty = tcSpliceExpr splice res_ty
581 tc_expr (HsBracket brack)  res_ty = do  { e <- tcBracket brack res_ty
582                                         ; return (unLoc e) }
583 #endif /* GHCI */
584 \end{code}
585
586
587 %************************************************************************
588 %*                                                                      *
589                 Catch-all
590 %*                                                                      *
591 %************************************************************************
592
593 \begin{code}
594 tc_expr other _ = pprPanic "tcMonoExpr" (ppr other)
595 \end{code}
596
597
598 %************************************************************************
599 %*                                                                      *
600 \subsection{@tcApp@ typchecks an application}
601 %*                                                                      *
602 %************************************************************************
603
604 \begin{code}
605
606 tcApp :: LHsExpr Name -> [LHsExpr Name]         -- Function and args
607       -> Expected TcRhoType                     -- Expected result type of application
608       -> TcM (HsExpr TcId)                      -- Translated fun and args
609
610 tcApp (L _ (HsApp e1 e2)) args res_ty 
611   = tcApp e1 (e2:args) res_ty           -- Accumulate the arguments
612
613 tcApp fun args res_ty
614   = do  { (fun', fun_tvs, fun_tau) <- tcFun fun         -- Type-check the function
615
616         -- Extract its argument types
617         ; (expected_arg_tys, actual_res_ty)
618               <- addErrCtxt (wrongArgsCtxt "too many" fun args) $ do
619                  { traceTc (text "tcApp" <+> (ppr fun $$ ppr fun_tau))
620                  ; unifyFunTys (length args) fun_tau }
621
622
623         ; case res_ty of
624             Check _ -> do       -- Connect to result type first
625                                 -- See Note [Push result type in]
626                 { co_fn    <- tcResult fun args res_ty actual_res_ty
627                 ; the_app' <- tcArgs fun fun' args expected_arg_tys
628                 ; traceTc (text "tcApp: check" <+> vcat [ppr fun <+> ppr args,
629                                                          ppr the_app', ppr actual_res_ty])
630                 ; returnM (co_fn <$> the_app') }
631
632             Infer _ -> do       -- Type check args first, then
633                                 -- refine result type, then do tcResult
634                 { the_app'       <- tcArgs fun fun' args expected_arg_tys
635                 ; actual_res_ty' <- refineResultTy fun_tvs actual_res_ty
636                 ; co_fn          <- tcResult fun args res_ty actual_res_ty'
637                 ; traceTc (text "tcApp: infer" <+> vcat [ppr fun <+> ppr args, ppr the_app',
638                                                          ppr actual_res_ty, ppr actual_res_ty'])
639                 ; returnM (co_fn <$> the_app') }
640         }
641
642 --      Note [Push result type in]
643 --
644 -- Unify with expected result before (was: after) type-checking the args
645 -- so that the info from res_ty (was: args) percolates to args (was actual_res_ty).
646 -- This is when we might detect a too-few args situation.
647 -- (One can think of cases when the opposite order would give
648 -- a better error message.)
649 -- [March 2003: I'm experimenting with putting this first.  Here's an 
650 --              example where it actually makes a real difference
651 --    class C t a b | t a -> b
652 --    instance C Char a Bool
653 --
654 --    data P t a = forall b. (C t a b) => MkP b
655 --    data Q t   = MkQ (forall a. P t a)
656
657 --    f1, f2 :: Q Char;
658 --    f1 = MkQ (MkP True)
659 --    f2 = MkQ (MkP True :: forall a. P Char a)
660 --
661 -- With the change, f1 will type-check, because the 'Char' info from
662 -- the signature is propagated into MkQ's argument. With the check
663 -- in the other order, the extra signature in f2 is reqd.]
664
665 ----------------
666 tcFun :: LHsExpr Name -> TcM (LHsExpr TcId, [TcTyVar], TcRhoType)
667 -- Instantiate the function, returning the type variables used
668 -- If the function isn't simple, infer its type, and return no 
669 -- type variables
670 tcFun (L loc (HsVar f)) = setSrcSpan loc $ do
671                           { (fun', tvs, fun_tau) <- tcId f
672                           ; return (L loc fun', tvs, fun_tau) }
673 tcFun fun = do { (fun', fun_tau) <- tcInfer (tcMonoExpr fun)
674                ; return (fun', [], fun_tau) }
675
676 ----------------
677 tcArgs :: LHsExpr Name                          -- The function (for error messages)
678        -> LHsExpr TcId                          -- The function (to build into result)
679        -> [LHsExpr Name] -> [TcSigmaType]       -- Actual arguments and expected arg types
680        -> TcM (HsExpr TcId)                     -- Resulting application
681
682 tcArgs fun fun' args expected_arg_tys
683   = do  { args' <- mappM (tcArg fun) (zip3 args expected_arg_tys [1..])
684         ; return (unLoc (foldl mkHsApp fun' args')) }
685
686 tcArg :: LHsExpr Name                           -- The function (for error messages)
687        -> (LHsExpr Name, TcSigmaType, Int)      -- Actual argument and expected arg type
688        -> TcM (LHsExpr TcId)                    -- Resulting argument
689 tcArg fun (arg, ty, arg_no) = addErrCtxt (funAppCtxt fun arg arg_no)
690                                          (tcCheckSigma arg ty)
691
692 ----------------
693 tcResult fun args res_ty actual_res_ty
694   = addErrCtxtM (checkArgsCtxt fun args res_ty actual_res_ty)
695                 (tcSubExp res_ty actual_res_ty)
696
697 ----------------
698 -- If an error happens we try to figure out whether the
699 -- function has been given too many or too few arguments,
700 -- and say so.
701 -- The ~(Check...) is because in the Infer case the tcSubExp 
702 -- definitely won't fail, so we can be certain we're in the Check branch
703 checkArgsCtxt fun args (Infer _) actual_res_ty tidy_env
704   = return (tidy_env, ptext SLIT("Urk infer"))
705
706 checkArgsCtxt fun args (Check expected_res_ty) actual_res_ty tidy_env
707   = zonkTcType expected_res_ty    `thenM` \ exp_ty' ->
708     zonkTcType actual_res_ty      `thenM` \ act_ty' ->
709     let
710       (env1, exp_ty'') = tidyOpenType tidy_env exp_ty'
711       (env2, act_ty'') = tidyOpenType env1     act_ty'
712       (exp_args, _)    = tcSplitFunTys exp_ty''
713       (act_args, _)    = tcSplitFunTys act_ty''
714
715       len_act_args     = length act_args
716       len_exp_args     = length exp_args
717
718       message | len_exp_args < len_act_args = wrongArgsCtxt "too few" fun args
719               | len_exp_args > len_act_args = wrongArgsCtxt "too many" fun args
720               | otherwise                   = appCtxt fun args
721     in
722     returnM (env2, message)
723
724 ----------------
725 refineResultTy :: [TcTyVar]     -- Newly instantiated meta-tyvars of the function
726                -> TcType        -- Result type, instantiated with those tyvars
727                -> TcM TcType    -- Refined result type
728 -- De-wobblify the result type, by taking account what we learned 
729 -- from type-checking the arguments.  Just one level of de-wobblification
730 -- though.  What a hack! 
731 refineResultTy tvs res_ty
732   = do  { mb_prs <- mapM mk_pr tvs
733         ; let subst = mkTopTvSubst (catMaybes mb_prs)
734         ; return (substTy subst res_ty) }
735   where
736     mk_pr tv = do { details <- readMetaTyVar tv
737                   ; case details of
738                         Indirect ty -> return (Just (tv,ty))
739                         other       -> return Nothing 
740                   }
741 \end{code}
742
743
744 %************************************************************************
745 %*                                                                      *
746 \subsection{@tcId@ typchecks an identifier occurrence}
747 %*                                                                      *
748 %************************************************************************
749
750 tcId instantiates an occurrence of an Id.
751 The instantiate_it loop runs round instantiating the Id.
752 It has to be a loop because we are now prepared to entertain
753 types like
754         f:: forall a. Eq a => forall b. Baz b => tau
755 We want to instantiate this to
756         f2::tau         {f2 = f1 b (Baz b), f1 = f a (Eq a)}
757
758 The -fno-method-sharing flag controls what happens so far as the LIE
759 is concerned.  The default case is that for an overloaded function we 
760 generate a "method" Id, and add the Method Inst to the LIE.  So you get
761 something like
762         f :: Num a => a -> a
763         f = /\a (d:Num a) -> let m = (+) a d in \ (x:a) -> m x x
764 If you specify -fno-method-sharing, the dictionary application 
765 isn't shared, so we get
766         f :: Num a => a -> a
767         f = /\a (d:Num a) (x:a) -> (+) a d x x
768 This gets a bit less sharing, but
769         a) it's better for RULEs involving overloaded functions
770         b) perhaps fewer separated lambdas
771
772 \begin{code}
773 tcId :: Name -> TcM (HsExpr TcId, [TcTyVar], TcRhoType)
774         -- Return the type variables at which the function
775         -- is instantiated, as well as the translated variable and its type
776
777 tcId name       -- Look up the Id and instantiate its type
778   = tcLookup name       `thenM` \ thing ->
779     case thing of {
780         AGlobal (AnId id) -> instantiate id
781                 -- A global cannot possibly be ill-staged
782                 -- nor does it need the 'lifting' treatment
783
784     ;   AGlobal (ADataCon con)  -- Similar, but instantiate the stupid theta too
785           -> do { (expr, tvs, tau) <- instantiate (dataConWrapId con)
786                 ; tcInstStupidTheta con (mkTyVarTys tvs)
787                 -- Remember to chuck in the constraints from the "silly context"
788                 ; return (expr, tvs, tau) }
789
790     ;   ATcId id th_level proc_level 
791           -> do { checkProcLevel id proc_level
792                 ; tc_local_id id th_level }
793
794     ;   other -> pprPanic "tcId" (ppr name $$ ppr thing)
795     }
796   where
797
798 #ifndef GHCI
799     tc_local_id id th_bind_lvl                  -- Non-TH case
800         = instantiate id
801
802 #else /* GHCI and TH is on */
803     tc_local_id id th_bind_lvl                  -- TH case
804         =       -- Check for cross-stage lifting
805           getStage                              `thenM` \ use_stage -> 
806           case use_stage of
807               Brack use_lvl ps_var lie_var
808                 | use_lvl > th_bind_lvl 
809                 ->      -- E.g. \x -> [| h x |]
810                 -- We must behave as if the reference to x was
811                 --      h $(lift x)     
812                 -- We use 'x' itself as the splice proxy, used by 
813                 -- the desugarer to stitch it all back together.
814                 -- If 'x' occurs many times we may get many identical
815                 -- bindings of the same splice proxy, but that doesn't
816                 -- matter, although it's a mite untidy.
817                 let
818                     id_ty = idType id
819                 in
820                 checkTc (isTauTy id_ty) (polySpliceErr id)      `thenM_` 
821                     -- If x is polymorphic, its occurrence sites might
822                     -- have different instantiations, so we can't use plain
823                     -- 'x' as the splice proxy name.  I don't know how to 
824                     -- solve this, and it's probably unimportant, so I'm
825                     -- just going to flag an error for now
826
827                 setLIEVar lie_var       (
828                 newMethodFromName orig id_ty DsMeta.liftName    `thenM` \ lift ->
829                         -- Put the 'lift' constraint into the right LIE
830         
831                 -- Update the pending splices
832                 readMutVar ps_var                       `thenM` \ ps ->
833                 writeMutVar ps_var ((name, nlHsApp (nlHsVar lift) (nlHsVar id)) : ps)   `thenM_`
834         
835                 returnM (HsVar id, [], id_ty))
836
837               other -> 
838                 checkWellStaged (quotes (ppr id)) th_bind_lvl use_stage `thenM_`
839                 instantiate id
840 #endif /* GHCI */
841
842     instantiate :: TcId -> TcM (HsExpr TcId, [TcTyVar], TcRhoType)
843     instantiate fun_id = loop (HsVar fun_id) [] (idType fun_id)
844
845     loop (HsVar fun_id) tvs fun_ty
846         | want_method_inst fun_ty
847         = tcInstType fun_ty             `thenM` \ (tyvars, theta, tau) ->
848           newMethodWithGivenTy orig fun_id 
849                 (mkTyVarTys tyvars) theta tau   `thenM` \ meth_id ->
850           loop (HsVar meth_id) (tvs ++ tyvars) tau
851
852     loop fun tvs fun_ty 
853         | isSigmaTy fun_ty
854         = tcInstCall orig fun_ty        `thenM` \ (inst_fn, new_tvs, tau) ->
855           loop (inst_fn <$> fun) (tvs ++ new_tvs) tau
856
857         | otherwise
858         = returnM (fun, tvs, fun_ty)
859
860         --      Hack Alert (want_method_inst)!
861         -- If   f :: (%x :: T) => Int -> Int
862         -- Then if we have two separate calls, (f 3, f 4), we cannot
863         -- make a method constraint that then gets shared, thus:
864         --      let m = f %x in (m 3, m 4)
865         -- because that loses the linearity of the constraint.
866         -- The simplest thing to do is never to construct a method constraint
867         -- in the first place that has a linear implicit parameter in it.
868     want_method_inst fun_ty 
869         | opt_NoMethodSharing = False   
870         | otherwise           = case tcSplitSigmaTy fun_ty of
871                                   (_,[],_)    -> False  -- Not overloaded
872                                   (_,theta,_) -> not (any isLinearPred theta)
873
874     orig = OccurrenceOf name
875 \end{code}
876
877 %************************************************************************
878 %*                                                                      *
879 \subsection{Record bindings}
880 %*                                                                      *
881 %************************************************************************
882
883 Game plan for record bindings
884 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
885 1. Find the TyCon for the bindings, from the first field label.
886
887 2. Instantiate its tyvars and unify (T a1 .. an) with expected_ty.
888
889 For each binding field = value
890
891 3. Instantiate the field type (from the field label) using the type
892    envt from step 2.
893
894 4  Type check the value using tcArg, passing the field type as 
895    the expected argument type.
896
897 This extends OK when the field types are universally quantified.
898
899         
900 \begin{code}
901 tcRecordBinds
902         :: TyCon                -- Type constructor for the record
903         -> [TcType]             -- Args of this type constructor
904         -> HsRecordBinds Name
905         -> TcM (HsRecordBinds TcId)
906
907 tcRecordBinds tycon ty_args rbinds
908   = mappM do_bind rbinds
909   where
910     tenv = zipTopTvSubst (tyConTyVars tycon) ty_args
911
912     do_bind (L loc field_lbl, rhs)
913       = addErrCtxt (fieldCtxt field_lbl)        $
914         let
915             field_ty  = tyConFieldType tycon field_lbl
916             field_ty' = substTy tenv field_ty
917         in
918         tcCheckSigma rhs field_ty'              `thenM` \ rhs' ->
919         tcLookupId field_lbl                    `thenM` \ sel_id ->
920         ASSERT( isRecordSelector sel_id )
921         returnM (L loc sel_id, rhs')
922
923 tyConFieldType :: TyCon -> FieldLabel -> Type
924 tyConFieldType tycon field_lbl
925   = case [ty | (f,ty,_) <- tyConFields tycon, f == field_lbl] of
926         (ty:other) -> ASSERT( null other) ty
927                 -- This lookup and assertion will surely succeed, because
928                 -- we check that the fields are indeed record selectors
929                 -- before calling tcRecordBinds
930
931 badFields rbinds data_con
932   = filter (not . (`elem` field_names)) (recBindFields rbinds)
933   where
934     field_names = dataConFieldLabels data_con
935
936 checkMissingFields :: DataCon -> HsRecordBinds Name -> TcM ()
937 checkMissingFields data_con rbinds
938   | null field_labels   -- Not declared as a record;
939                         -- But C{} is still valid if no strict fields
940   = if any isMarkedStrict field_strs then
941         -- Illegal if any arg is strict
942         addErrTc (missingStrictFields data_con [])
943     else
944         returnM ()
945                         
946   | otherwise           -- A record
947   = checkM (null missing_s_fields)
948            (addErrTc (missingStrictFields data_con missing_s_fields))   `thenM_`
949
950     doptM Opt_WarnMissingFields         `thenM` \ warn ->
951     checkM (not (warn && notNull missing_ns_fields))
952            (warnTc True (missingFields data_con missing_ns_fields))
953
954   where
955     missing_s_fields
956         = [ fl | (fl, str) <- field_info,
957                  isMarkedStrict str,
958                  not (fl `elem` field_names_used)
959           ]
960     missing_ns_fields
961         = [ fl | (fl, str) <- field_info,
962                  not (isMarkedStrict str),
963                  not (fl `elem` field_names_used)
964           ]
965
966     field_names_used = recBindFields rbinds
967     field_labels     = dataConFieldLabels data_con
968
969     field_info = zipEqual "missingFields"
970                           field_labels
971                           field_strs
972
973     field_strs = dataConStrictMarks data_con
974 \end{code}
975
976 %************************************************************************
977 %*                                                                      *
978 \subsection{@tcCheckRhos@ typechecks a {\em list} of expressions}
979 %*                                                                      *
980 %************************************************************************
981
982 \begin{code}
983 tcCheckRhos :: [LHsExpr Name] -> [TcType] -> TcM [LHsExpr TcId]
984
985 tcCheckRhos [] [] = returnM []
986 tcCheckRhos (expr:exprs) (ty:tys)
987  = tcCheckRho  expr  ty         `thenM` \ expr' ->
988    tcCheckRhos exprs tys        `thenM` \ exprs' ->
989    returnM (expr':exprs')
990 \end{code}
991
992
993 %************************************************************************
994 %*                                                                      *
995 \subsection{Literals}
996 %*                                                                      *
997 %************************************************************************
998
999 Overloaded literals.
1000
1001 \begin{code}
1002 tcLit :: HsLit -> Expected TcRhoType -> TcM (HsExpr TcId)
1003 tcLit lit res_ty 
1004   = zapExpectedTo res_ty (hsLitType lit)                `thenM_`
1005     returnM (HsLit lit)
1006 \end{code}
1007
1008
1009 %************************************************************************
1010 %*                                                                      *
1011 \subsection{Errors and contexts}
1012 %*                                                                      *
1013 %************************************************************************
1014
1015 Boring and alphabetical:
1016 \begin{code}
1017 arithSeqCtxt expr
1018   = hang (ptext SLIT("In an arithmetic sequence:")) 4 (ppr expr)
1019
1020 parrSeqCtxt expr
1021   = hang (ptext SLIT("In a parallel array sequence:")) 4 (ppr expr)
1022
1023 caseCtxt expr
1024   = hang (ptext SLIT("In the case expression:")) 4 (ppr expr)
1025
1026 caseScrutCtxt expr
1027   = hang (ptext SLIT("In the scrutinee of a case expression:")) 4 (ppr expr)
1028
1029 exprCtxt expr
1030   = hang (ptext SLIT("In the expression:")) 4 (ppr expr)
1031
1032 fieldCtxt field_name
1033   = ptext SLIT("In the") <+> quotes (ppr field_name) <+> ptext SLIT("field of a record")
1034
1035 funAppCtxt fun arg arg_no
1036   = hang (hsep [ ptext SLIT("In the"), speakNth arg_no, ptext SLIT("argument of"), 
1037                     quotes (ppr fun) <> text ", namely"])
1038          4 (quotes (ppr arg))
1039
1040 listCtxt expr
1041   = hang (ptext SLIT("In the list element:")) 4 (ppr expr)
1042
1043 parrCtxt expr
1044   = hang (ptext SLIT("In the parallel array element:")) 4 (ppr expr)
1045
1046 predCtxt expr
1047   = hang (ptext SLIT("In the predicate expression:")) 4 (ppr expr)
1048
1049 appCtxt fun args
1050   = ptext SLIT("In the application") <+> quotes (ppr the_app)
1051   where
1052     the_app = foldl mkHsApp fun args    -- Used in error messages
1053
1054 badFieldsUpd rbinds
1055   = hang (ptext SLIT("No constructor has all these fields:"))
1056          4 (pprQuotedList (recBindFields rbinds))
1057
1058 recordUpdCtxt expr = ptext SLIT("In the record update:") <+> ppr expr
1059 recordConCtxt expr = ptext SLIT("In the record construction:") <+> ppr expr
1060
1061 notSelector field
1062   = hsep [quotes (ppr field), ptext SLIT("is not a record selector")]
1063
1064 missingStrictFields :: DataCon -> [FieldLabel] -> SDoc
1065 missingStrictFields con fields
1066   = header <> rest
1067   where
1068     rest | null fields = empty  -- Happens for non-record constructors 
1069                                 -- with strict fields
1070          | otherwise   = colon <+> pprWithCommas ppr fields
1071
1072     header = ptext SLIT("Constructor") <+> quotes (ppr con) <+> 
1073              ptext SLIT("does not have the required strict field(s)") 
1074           
1075 missingFields :: DataCon -> [FieldLabel] -> SDoc
1076 missingFields con fields
1077   = ptext SLIT("Fields of") <+> quotes (ppr con) <+> ptext SLIT("not initialised:") 
1078         <+> pprWithCommas ppr fields
1079
1080 wrongArgsCtxt too_many_or_few fun args
1081   = hang (ptext SLIT("Probable cause:") <+> quotes (ppr fun)
1082                     <+> ptext SLIT("is applied to") <+> text too_many_or_few 
1083                     <+> ptext SLIT("arguments in the call"))
1084          4 (parens (ppr the_app))
1085   where
1086     the_app = foldl mkHsApp fun args    -- Used in error messages
1087
1088 #ifdef GHCI
1089 polySpliceErr :: Id -> SDoc
1090 polySpliceErr id
1091   = ptext SLIT("Can't splice the polymorphic local variable") <+> quotes (ppr id)
1092 #endif
1093 \end{code}