2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
4 \section[CoreLint]{A ``lint'' pass to check for Core correctness}
12 #include "HsVersions.h"
14 import IO ( hPutStr, stderr )
16 import CmdLineOpts ( opt_D_show_passes, opt_DoCoreLinting )
18 import CoreUtils ( idSpecVars )
21 import Kind ( hasMoreBoxityInfo, Kind{-instance-} )
22 import Literal ( literalType, Literal{-instance-} )
23 import Id ( idType, isBottomingId, dataConRepType, isDataCon, isAlgCon,
24 dataConArgTys, GenId{-instances-},
26 unionIdSets, elementOfIdSet, IdSet,
29 import Maybes ( catMaybes )
30 import Name ( isLocallyDefined, getSrcLoc, Name{-instance NamedThing-},
34 import ErrUtils ( doIfSet, ghcExit )
35 import PrimOp ( primOpType )
36 import PrimRep ( PrimRep(..) )
37 import SrcLoc ( SrcLoc )
38 import Type ( mkFunTy, splitFunTy_maybe, mkForAllTy,
39 splitForAllTy_maybe, tyVarsOfType,
40 isUnpointedType, typeKind, instantiateTy,
41 splitAlgTyConApp_maybe, Type
43 import TyCon ( TyCon, isPrimTyCon, isDataTyCon )
44 import TyVar ( TyVar, tyVarKind, mkTyVarEnv,
46 emptyTyVarSet, mkTyVarSet, isEmptyTyVarSet,
47 minusTyVarSet, elementOfTyVarSet, tyVarSetToList,
48 unionTyVarSets, intersectTyVarSets
50 import ErrUtils ( ErrMsg )
51 import Unique ( Unique )
52 import Util ( zipEqual )
55 infixr 9 `thenL`, `seqL`, `thenMaybeL`
58 %************************************************************************
60 \subsection[lintCoreBindings]{@lintCoreBindings@: Top-level interface}
62 %************************************************************************
64 Checks that a set of core bindings is well-formed. The PprStyle and String
65 just control what we print in the event of an error. The Bool value
66 indicates whether we have done any specialisation yet (in which case we do
71 (b) Out-of-scope type variables
72 (c) Out-of-scope local variables
75 If we have done specialisation the we check that there are
76 (a) No top-level bindings of primitive (unboxed type)
81 -- Things are *not* OK if:
83 -- * Unsaturated type app before specialisation has been done;
85 -- * Oversaturated type app after specialisation (eta reduction
86 -- may well be happening...);
88 -- Note: checkTyApp is usually followed by a call to checkSpecTyApp.
92 lintCoreBindings :: String -> Bool -> [CoreBinding] -> IO ()
94 lintCoreBindings whoDunnit spec_done binds
95 | not opt_DoCoreLinting
98 lintCoreBindings whoDunnit spec_done binds
99 = case (initL (lint_binds binds) spec_done) of
100 Nothing -> doIfSet opt_D_show_passes
101 (hPutStr stderr ("*** Core Linted result of " ++ whoDunnit ++ "\n"))
103 Just bad_news -> printDump (display bad_news) >>
106 lint_binds [] = returnL ()
107 lint_binds (bind:binds)
108 = lintCoreBinding bind `thenL` \binders ->
109 addInScopeVars binders (lint_binds binds)
113 text ("*** Core Lint Errors: in result of " ++ whoDunnit ++ " ***"),
115 ptext SLIT("*** Offending Program ***"),
116 pprCoreBindings binds,
117 ptext SLIT("*** End of Offense ***")
121 %************************************************************************
123 \subsection[lintUnfolding]{lintUnfolding}
125 %************************************************************************
127 We use this to check all unfoldings that come in from interfaces
128 (it is very painful to catch errors otherwise):
131 lintUnfolding :: SrcLoc -> CoreExpr -> Maybe CoreExpr
133 lintUnfolding locn expr
135 (initL (addLoc (ImportedUnfolding locn) (lintCoreExpr expr))
136 True{-pretend spec done-})
140 pprTrace "WARNING: Discarded bad unfolding from interface:\n"
142 ptext SLIT("*** Bad unfolding ***"),
144 ptext SLIT("*** End unfolding ***")])
148 %************************************************************************
150 \subsection[lintCoreBinding]{lintCoreBinding}
152 %************************************************************************
154 Check a core binding, returning the list of variables bound.
157 lintCoreBinding :: CoreBinding -> LintM [Id]
159 lintCoreBinding (NonRec binder rhs)
160 = lintSingleBinding (binder,rhs) `seqL` returnL [binder]
162 lintCoreBinding (Rec pairs)
163 = addInScopeVars binders (
164 mapL lintSingleBinding pairs `seqL` returnL binders
167 binders = [b | (b,_) <- pairs]
169 lintSingleBinding (binder,rhs)
170 = addLoc (RhsOf binder) (
175 -- Check match to RHS type
177 Nothing -> returnL ()
178 Just ty -> checkTys (idType binder) ty (mkRhsMsg binder ty))
181 -- Check (not isUnpointedType)
182 checkIfSpecDoneL (not (isUnpointedType (idType binder)))
183 (mkRhsPrimMsg binder rhs) `seqL`
185 -- Check whether binder's specialisations contain any out-of-scope variables
186 ifSpecDoneL (mapL (checkSpecIdInScope binder) spec_vars `seqL` returnL ())
188 -- We should check the unfolding, if any, but this is tricky because
189 -- the unfolding is a SimplifiableCoreExpr. Give up for now.
192 spec_vars = idSpecVars binder
196 %************************************************************************
198 \subsection[lintCoreExpr]{lintCoreExpr}
200 %************************************************************************
203 lintCoreExpr :: CoreExpr -> LintM (Maybe Type) -- Nothing if error found
205 lintCoreExpr (Var var)
206 | isAlgCon var = returnL (Just (idType var))
207 -- Micro-hack here... Class decls generate applications of their
208 -- dictionary constructor, but don't generate a binding for the
209 -- constructor (since it would never be used). After a single round
210 -- of simplification, these dictionary constructors have been
211 -- inlined (from their UnfoldInfo) to CoCons. Just between
212 -- desugaring and simplfication, though, they appear as naked, unbound
213 -- variables as the function in an application.
214 -- The hack here simply doesn't check for out-of-scope-ness for
215 -- data constructors (at least, in a function position).
217 | otherwise = checkIdInScope var `seqL` returnL (Just (idType var))
219 lintCoreExpr (Lit lit) = returnL (Just (literalType lit))
221 lintCoreExpr (Note (Coerce to_ty from_ty) expr)
222 = lintCoreExpr expr `thenMaybeL` \ expr_ty ->
224 lintTy from_ty `seqL`
225 checkTys from_ty expr_ty (mkCoerceErr from_ty expr_ty) `seqL`
228 lintCoreExpr (Note other_note expr)
231 lintCoreExpr (Let binds body)
232 = lintCoreBinding binds `thenL` \binders ->
233 if (null binders) then
234 lintCoreExpr body -- Can't add a new source location
236 addLoc (BodyOfLetRec binders)
237 (addInScopeVars binders (lintCoreExpr body))
239 lintCoreExpr e@(Con con args)
240 = checkL (isDataCon con) (mkConErrMsg e) `seqL`
241 lintCoreArgs {-False-} e (dataConRepType con) args
242 -- Note: we don't check for primitive types in these arguments
244 lintCoreExpr e@(Prim op args)
245 = lintCoreArgs {-True-} e (primOpType op) args
246 -- Note: we do check for primitive types in these arguments
248 lintCoreExpr e@(App fun@(Var v) arg) | isBottomingId v
249 = lintCoreExpr fun `thenMaybeL` \ ty -> lintCoreArg {-False-} e ty arg
250 -- Note: we don't check for primitive types in argument to 'error'
252 lintCoreExpr e@(App fun arg)
253 = lintCoreExpr fun `thenMaybeL` \ty -> lintCoreArg {-True-} e ty arg
254 -- Note: we do check for primitive types in this argument
256 lintCoreExpr (Lam vb@(ValBinder var) expr)
257 = addLoc (LambdaBodyOf vb)
258 (addInScopeVars [var]
259 (lintCoreExpr expr `thenMaybeL` \ty ->
260 returnL (Just (mkFunTy (idType var) ty))))
262 lintCoreExpr (Lam tb@(TyBinder tyvar) expr)
263 = addLoc (LambdaBodyOf tb) $
264 addInScopeTyVars [tyvar] $
265 lintCoreExpr expr `thenMaybeL` \ ty ->
266 returnL (Just(mkForAllTy tyvar ty))
268 lintCoreExpr e@(Case scrut alts)
269 = lintCoreExpr scrut `thenMaybeL` \ty ->
273 %************************************************************************
275 \subsection[lintCoreArgs]{lintCoreArgs}
277 %************************************************************************
279 The boolean argument indicates whether we should flag type
280 applications to primitive types as being errors.
283 lintCoreArgs :: {-Bool ->-} CoreExpr -> Type -> [CoreArg] -> LintM (Maybe Type)
285 lintCoreArgs _ ty [] = returnL (Just ty)
286 lintCoreArgs e ty (a : args)
287 = lintCoreArg e ty a `thenMaybeL` \ res ->
288 lintCoreArgs e res args
291 %************************************************************************
293 \subsection[lintCoreArg]{lintCoreArg}
295 %************************************************************************
298 lintCoreArg :: {-Bool ->-} CoreExpr -> Type -> CoreArg -> LintM (Maybe Type)
300 lintCoreArg e ty (LitArg lit)
301 = -- Make sure function type matches argument
302 case (splitFunTy_maybe ty) of
303 Just (arg,res) | (lit_ty == arg) -> returnL(Just res)
304 _ -> addErrL (mkAppMsg ty lit_ty e) `seqL` returnL Nothing
306 lit_ty = literalType lit
308 lintCoreArg e ty (VarArg v)
309 = -- Make sure variable is bound
310 checkIdInScope v `seqL`
311 -- Make sure function type matches argument
312 case (splitFunTy_maybe ty) of
313 Just (arg,res) | (var_ty == arg) -> returnL(Just res)
314 _ -> addErrL (mkAppMsg ty var_ty e) `seqL` returnL Nothing
318 lintCoreArg e ty a@(TyArg arg_ty)
319 = lintTy arg_ty `seqL`
320 checkTyVarsInScope (tyVarsOfType arg_ty) `seqL`
321 case (splitForAllTy_maybe ty) of
322 Nothing -> addErrL (mkTyAppMsg SLIT("Illegal") ty arg_ty e) `seqL` returnL Nothing
326 tyvar_kind = tyVarKind tyvar
327 argty_kind = typeKind arg_ty
329 if argty_kind `hasMoreBoxityInfo` tyvar_kind
330 -- Arg type might be boxed for a function with an uncommitted
331 -- tyvar; notably this is used so that we can give
332 -- error :: forall a:*. String -> a
333 -- and then apply it to both boxed and unboxed types.
335 returnL(Just(instantiateTy (mkTyVarEnv [(tyvar,arg_ty)]) body))
337 pprTrace "lintCoreArg:kinds:" (hsep [ppr tyvar_kind, ppr argty_kind]) $
338 addErrL (mkKindErrMsg tyvar arg_ty e) `seqL` returnL Nothing
341 %************************************************************************
343 \subsection[lintCoreAlts]{lintCoreAlts}
345 %************************************************************************
348 lintCoreAlts :: CoreCaseAlts
349 -> Type -- Type of scrutinee
350 -- -> TyCon -- TyCon pinned on the case
351 -> LintM (Maybe Type) -- Type of alternatives
353 lintCoreAlts whole_alts@(AlgAlts alts deflt) ty --tycon
354 = -- Check tycon is not a primitive tycon
355 -- addErrIfL (isPrimTyCon tycon) (mkCasePrimMsg tycon)
357 -- Check we are scrutinising a proper datatype
359 -- addErrIfL (not (tyConFamilySize tycon >= 1)) (mkCaseAbstractMsg tycon)
362 `thenL` \maybe_deflt_ty ->
363 mapL (lintAlgAlt ty {-tycon-}) alts
364 `thenL` \maybe_alt_tys ->
365 -- Check the result types
366 case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
367 [] -> returnL Nothing
369 (first_ty:tys) -> mapL check tys `seqL`
370 returnL (Just first_ty)
372 check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
374 lintCoreAlts whole_alts@(PrimAlts alts deflt) ty --tycon
375 = -- Check tycon is a primitive tycon
376 -- addErrIfL (not (isPrimTyCon tycon)) (mkCaseNotPrimMsg tycon)
378 mapL (lintPrimAlt ty) alts
379 `thenL` \maybe_alt_tys ->
381 `thenL` \maybe_deflt_ty ->
382 -- Check the result types
383 case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
384 [] -> returnL Nothing
386 (first_ty:tys) -> mapL check tys `seqL`
387 returnL (Just first_ty)
389 check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
391 lintAlgAlt scrut_ty (con,args,rhs)
392 = (case splitAlgTyConApp_maybe scrut_ty of
393 Just (tycon, tys_applied, cons) | isDataTyCon tycon ->
395 arg_tys = dataConArgTys con tys_applied
397 checkL (con `elem` cons) (mkAlgAltMsg2 scrut_ty con) `seqL`
398 checkL (length arg_tys == length args) (mkAlgAltMsg3 con args)
400 mapL check (zipEqual "lintAlgAlt" arg_tys args) `seqL`
403 other -> addErrL (mkAlgAltMsg1 scrut_ty)
405 addInScopeVars args (
409 check (ty, arg) = checkTys ty (idType arg) (mkAlgAltMsg4 ty arg)
411 -- elem: yes, the elem-list here can sometimes be long-ish,
412 -- but as it's use-once, probably not worth doing anything different
413 -- We give it its own copy, so it isn't overloaded.
415 elem x (y:ys) = x==y || elem x ys
417 lintPrimAlt ty alt@(lit,rhs)
418 = checkTys (literalType lit) ty (mkPrimAltMsg alt) `seqL`
421 lintDeflt NoDefault _ = returnL Nothing
422 lintDeflt deflt@(BindDefault binder rhs) ty
423 = checkTys (idType binder) ty (mkDefltMsg deflt) `seqL`
424 addInScopeVars [binder] (lintCoreExpr rhs)
427 %************************************************************************
429 \subsection[lint-types]{Types}
431 %************************************************************************
434 lintTy :: Type -> LintM ()
435 lintTy ty = returnL ()
436 -- ToDo: Check that ty is well-kinded and has no unbound tyvars
440 %************************************************************************
442 \subsection[lint-monad]{The Lint monad}
444 %************************************************************************
447 type LintM a = Bool -- True <=> specialisation has been done
448 -> [LintLocInfo] -- Locations
449 -> IdSet -- Local vars in scope
450 -> TyVarSet -- Local tyvars in scope
451 -> Bag ErrMsg -- Error messages so far
452 -> (a, Bag ErrMsg) -- Result and error messages (if any)
455 = RhsOf Id -- The variable bound
456 | LambdaBodyOf CoreBinder -- The lambda-binder
457 | BodyOfLetRec [Id] -- One of the binders
458 | ImportedUnfolding SrcLoc -- Some imported unfolding (ToDo: say which)
460 instance Outputable LintLocInfo where
462 = ppr (getSrcLoc v) <> colon <+>
463 brackets (ptext SLIT("RHS of") <+> pp_binders [v])
465 ppr (LambdaBodyOf (ValBinder b))
466 = ppr (getSrcLoc b) <> colon <+>
467 brackets (ptext SLIT("in body of lambda with binder") <+> pp_binder b)
469 ppr (LambdaBodyOf (TyBinder b))
470 = ppr (getSrcLoc b) <> colon <+>
471 brackets (ptext SLIT("in body of lambda with type binder") <+> ppr b)
473 ppr (BodyOfLetRec bs)
474 = ppr (getSrcLoc (head bs)) <> colon <+>
475 brackets (ptext SLIT("in body of letrec with binders") <+> pp_binders bs)
477 ppr (ImportedUnfolding locn)
478 = ppr locn <> colon <+>
479 brackets (ptext SLIT("in an imported unfolding"))
481 pp_binders :: [Id] -> SDoc
482 pp_binders bs = sep (punctuate comma (map pp_binder bs))
484 pp_binder :: Id -> SDoc
485 pp_binder b = hsep [ppr b, text "::", ppr (idType b)]
489 initL :: LintM a -> Bool -> Maybe ErrMsg
491 = case (m spec_done [] emptyIdSet emptyTyVarSet emptyBag) of { (_, errs) ->
492 if isEmptyBag errs then
495 Just (vcat (bagToList errs))
498 returnL :: a -> LintM a
499 returnL r spec loc scope tyscope errs = (r, errs)
501 thenL :: LintM a -> (a -> LintM b) -> LintM b
502 thenL m k spec loc scope tyscope errs
503 = case m spec loc scope tyscope errs of
504 (r, errs') -> k r spec loc scope tyscope errs'
506 seqL :: LintM a -> LintM b -> LintM b
507 seqL m k spec loc scope tyscope errs
508 = case m spec loc scope tyscope errs of
509 (_, errs') -> k spec loc scope tyscope errs'
511 thenMaybeL :: LintM (Maybe a) -> (a -> LintM (Maybe b)) -> LintM (Maybe b)
512 thenMaybeL m k spec loc scope tyscope errs
513 = case m spec loc scope tyscope errs of
514 (Nothing, errs2) -> (Nothing, errs2)
515 (Just r, errs2) -> k r spec loc scope tyscope errs2
517 mapL :: (a -> LintM b) -> [a] -> LintM [b]
518 mapL f [] = returnL []
521 mapL f xs `thenL` \ rs ->
524 mapMaybeL :: (a -> LintM (Maybe b)) -> [a] -> LintM (Maybe [b])
525 -- Returns Nothing if anything fails
526 mapMaybeL f [] = returnL (Just [])
528 = f x `thenMaybeL` \ r ->
529 mapMaybeL f xs `thenMaybeL` \ rs ->
530 returnL (Just (r:rs))
534 checkL :: Bool -> ErrMsg -> LintM ()
535 checkL True msg spec loc scope tyscope errs = ((), errs)
536 checkL False msg spec loc scope tyscope errs = ((), addErr errs msg loc)
538 checkIfSpecDoneL :: Bool -> ErrMsg -> LintM ()
539 checkIfSpecDoneL True msg spec loc scope tyscope errs = ((), errs)
540 checkIfSpecDoneL False msg True loc scope tyscope errs = ((), addErr errs msg loc)
541 checkIfSpecDoneL False msg False loc scope tyscope errs = ((), errs)
543 ifSpecDoneL :: LintM () -> LintM ()
544 ifSpecDoneL m False loc scope tyscope errs = ((), errs)
545 ifSpecDoneL m True loc scope tyscope errs = m True loc scope tyscope errs
547 addErrL :: ErrMsg -> LintM ()
548 addErrL msg spec loc scope tyscope errs = ((), addErr errs msg loc)
550 addErr :: Bag ErrMsg -> ErrMsg -> [LintLocInfo] -> Bag ErrMsg
552 addErr errs_so_far msg locs
553 = ASSERT (not (null locs))
554 errs_so_far `snocBag` (hang (ppr (head locs)) 4 msg)
556 addLoc :: LintLocInfo -> LintM a -> LintM a
557 addLoc extra_loc m spec loc scope tyscope errs
558 = m spec (extra_loc:loc) scope tyscope errs
560 addInScopeVars :: [Id] -> LintM a -> LintM a
561 addInScopeVars ids m spec loc scope tyscope errs
562 = -- We check if these "new" ids are already
563 -- in scope, i.e., we have *shadowing* going on.
564 -- For now, it's just a "trace"; we may make
565 -- a real error out of it...
567 new_set = mkIdSet ids
569 -- shadowed = scope `intersectIdSets` new_set
571 -- After adding -fliberate-case, Simon decided he likes shadowed
572 -- names after all. WDP 94/07
573 -- (if isEmptyUniqSet shadowed
575 -- else pprTrace "Shadowed vars:" (ppr (uniqSetToList shadowed))) (
576 m spec loc (scope `unionIdSets` new_set) tyscope errs
579 addInScopeTyVars :: [TyVar] -> LintM a -> LintM a
580 addInScopeTyVars tyvars m spec loc scope tyscope errs
581 = m spec loc scope (tyscope `unionTyVarSets` new_set) errs
583 new_set = mkTyVarSet tyvars
588 checkIdInScope :: Id -> LintM ()
590 = checkInScope (ptext SLIT("is out of scope")) id
592 checkSpecIdInScope :: Id -> Id -> LintM ()
593 checkSpecIdInScope binder id
594 = checkInScope msg id
596 msg = ptext SLIT("is out of scope inside specialisation info for") <+>
599 checkInScope :: SDoc -> Id -> LintM ()
600 checkInScope loc_msg id spec loc scope tyscope errs
604 if isLocallyDefined id_name && not (id `elementOfIdSet` scope) then
605 ((), addErr errs (hsep [ppr id, loc_msg]) loc)
609 checkTyVarsInScope :: TyVarSet -> LintM ()
610 checkTyVarsInScope tyvars spec loc scope tyscope errs
611 -- | not (isEmptyTyVarSet out_of_scope) = ((), errs')
612 | otherwise = ((), errs)
614 out_of_scope = tyvars `minusTyVarSet` tyscope
616 foldr (\ tv errs -> addErr errs (hsep [ppr tv, ptext SLIT("is out of scope")]) loc)
618 (tyVarSetToList out_of_scope)
620 checkTys :: Type -> Type -> ErrMsg -> LintM ()
621 checkTys ty1 ty2 msg spec loc scope tyscope errs
622 = if ty1 == ty2 then ((), errs) else ((), addErr errs msg loc)
627 = ($$) (ptext SLIT("Application of newtype constructor:"))
631 mkCaseAltMsg :: CoreCaseAlts -> ErrMsg
633 = ($$) (ptext SLIT("Type of case alternatives not the same:"))
636 mkCaseAbstractMsg :: TyCon -> ErrMsg
637 mkCaseAbstractMsg tycon
638 = ($$) (ptext SLIT("An algebraic case on some weird type:"))
641 mkDefltMsg :: CoreCaseDefault -> ErrMsg
643 = ($$) (ptext SLIT("Binder in case default doesn't match type of scrutinee:"))
646 mkAppMsg :: Type -> Type -> CoreExpr -> ErrMsg
647 mkAppMsg fun arg expr
648 = vcat [ptext SLIT("Argument value doesn't match argument type:"),
649 hang (ptext SLIT("Fun type:")) 4 (ppr fun),
650 hang (ptext SLIT("Arg type:")) 4 (ppr arg),
651 hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
653 mkKindErrMsg :: TyVar -> Type -> CoreExpr -> ErrMsg
654 mkKindErrMsg tyvar arg_ty expr
655 = vcat [ptext SLIT("Kinds don't match in type application:"),
656 hang (ptext SLIT("Type variable:"))
657 4 (ppr tyvar <+> ptext SLIT("::") <+> ppr (tyVarKind tyvar)),
658 hang (ptext SLIT("Arg type:"))
659 4 (ppr arg_ty <+> ptext SLIT("::") <+> ppr (typeKind arg_ty)),
660 hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
662 mkTyAppMsg :: FAST_STRING -> Type -> Type -> CoreExpr -> ErrMsg
663 mkTyAppMsg msg ty arg expr
664 = vcat [hsep [ptext msg, ptext SLIT("type application:")],
665 hang (ptext SLIT("Exp type:"))
666 4 (ppr ty <+> ptext SLIT("::") <+> ppr (typeKind ty)),
667 hang (ptext SLIT("Arg type:"))
668 4 (ppr arg <+> ptext SLIT("::") <+> ppr (typeKind arg)),
669 hang (ptext SLIT("Expression:")) 4 (pprCoreExpr expr)]
671 mkAlgAltMsg1 :: Type -> ErrMsg
673 = ($$) (text "In some case statement, type of scrutinee is not a data type:")
676 mkAlgAltMsg2 :: Type -> Id -> ErrMsg
679 text "In some algebraic case alternative, constructor is not a constructor of scrutinee type:",
684 mkAlgAltMsg3 :: Id -> [Id] -> ErrMsg
685 mkAlgAltMsg3 con alts
687 text "In some algebraic case alternative, number of arguments doesn't match constructor:",
692 mkAlgAltMsg4 :: Type -> Id -> ErrMsg
695 text "In some algebraic case alternative, type of argument doesn't match data constructor:",
700 mkPrimAltMsg :: (Literal, CoreExpr) -> ErrMsg
703 (text "In a primitive case alternative, type of literal doesn't match type of scrutinee:")
706 mkRhsMsg :: Id -> Type -> ErrMsg
709 [hsep [ptext SLIT("The type of this binder doesn't match the type of its RHS:"),
711 hsep [ptext SLIT("Binder's type:"), ppr (idType binder)],
712 hsep [ptext SLIT("Rhs type:"), ppr ty]]
714 mkRhsPrimMsg :: Id -> CoreExpr -> ErrMsg
715 mkRhsPrimMsg binder rhs
716 = vcat [hsep [ptext SLIT("The type of this binder is primitive:"),
718 hsep [ptext SLIT("Binder's type:"), ppr (idType binder)]
721 mkCoerceErr from_ty expr_ty
722 = vcat [ptext SLIT("From-type of Coerce differs from type of enclosed expression"),
723 ptext SLIT("From-type:") <+> ppr from_ty,
724 ptext SLIT("Type of enclosed expr:") <+> ppr expr_ty