-lintCoreAlts :: CoreCaseAlts
- -> Type -- Type of scrutinee
--- -> TyCon -- TyCon pinned on the case
- -> LintM (Maybe Type) -- Type of alternatives
-
-lintCoreAlts whole_alts@(AlgAlts alts deflt) ty --tycon
- = -- Check tycon is not a primitive tycon
--- addErrIfL (isPrimTyCon tycon) (mkCasePrimMsg tycon)
--- `seqL`
- -- Check we are scrutinising a proper datatype
- -- (ToDo: robustify)
--- addErrIfL (not (tyConFamilySize tycon >= 1)) (mkCaseAbstractMsg tycon)
--- `seqL`
- lintDeflt deflt ty
- `thenL` \maybe_deflt_ty ->
- mapL (lintAlgAlt ty {-tycon-}) alts
- `thenL` \maybe_alt_tys ->
- -- Check the result types
- case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
- [] -> returnL Nothing
-
- (first_ty:tys) -> mapL check tys `seqL`
- returnL (Just first_ty)
- where
- check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
-
-lintCoreAlts whole_alts@(PrimAlts alts deflt) ty --tycon
- = -- Check tycon is a primitive tycon
--- addErrIfL (not (isPrimTyCon tycon)) (mkCaseNotPrimMsg tycon)
--- `seqL`
- mapL (lintPrimAlt ty) alts
- `thenL` \maybe_alt_tys ->
- lintDeflt deflt ty
- `thenL` \maybe_deflt_ty ->
- -- Check the result types
- case catMaybes (maybe_deflt_ty : maybe_alt_tys) of
- [] -> returnL Nothing
-
- (first_ty:tys) -> mapL check tys `seqL`
- returnL (Just first_ty)
- where
- check ty = checkTys first_ty ty (mkCaseAltMsg whole_alts)
-
-lintAlgAlt scrut_ty {-tycon-ToDo: use it!-} (con,args,rhs)
- = (case maybeAppDataTyConExpandingDicts scrut_ty of
- Nothing ->
- addErrL (mkAlgAltMsg1 scrut_ty)
- Just (tycon, tys_applied, cons) ->
- let
- arg_tys = dataConArgTys con tys_applied
- in
- checkL (con `elem` cons) (mkAlgAltMsg2 scrut_ty con) `seqL`
- checkL (length arg_tys == length args) (mkAlgAltMsg3 con args)
- `seqL`
- mapL check (zipEqual "lintAlgAlt" arg_tys args) `seqL`
- returnL ()
- ) `seqL`
- addInScopeVars args (
- lintCoreExpr rhs
- )
- where
- check (ty, arg) = checkTys ty (idType arg) (mkAlgAltMsg4 ty arg)
-
- -- elem: yes, the elem-list here can sometimes be long-ish,
- -- but as it's use-once, probably not worth doing anything different
- -- We give it its own copy, so it isn't overloaded.
- elem _ [] = False
- elem x (y:ys) = x==y || elem x ys
-
-lintPrimAlt ty alt@(lit,rhs)
- = checkTys (literalType lit) ty (mkPrimAltMsg alt) `seqL`
- lintCoreExpr rhs
-
-lintDeflt NoDefault _ = returnL Nothing
-lintDeflt deflt@(BindDefault binder rhs) ty
- = checkTys (idType binder) ty (mkDefltMsg deflt) `seqL`
- addInScopeVars [binder] (lintCoreExpr rhs)
+lintBinder :: Var -> LintM ()
+lintBinder var | isId var = lintId var >> return ()
+ | otherwise = return ()
+
+lintId :: Var -> LintM OutType
+-- ToDo: lint its rules
+lintId id
+ = do { checkL (not (isUnboxedTupleType (idType id)))
+ (mkUnboxedTupleMsg id)
+ -- No variable can be bound to an unboxed tuple.
+ ; lintTy (idType id) }
+
+lintTy :: InType -> LintM OutType
+-- Check the type, and apply the substitution to it
+-- ToDo: check the kind structure of the type
+lintTy ty
+ = do { ty' <- applySubst ty
+ ; mapM_ checkIdInScope (varSetElems (tyVarsOfType ty'))
+ ; return ty' }