; return (syn_tycons, concat alg_tyclss)
}}})
-- Finished with knot-tying now
; return (syn_tycons, concat alg_tyclss)
}}})
-- Finished with knot-tying now
tcFamInstDecl :: LTyClDecl Name -> TcM (Maybe TyThing) -- Nothing if error
tcFamInstDecl (L loc decl)
= -- Prime error recovery, set source location
tcFamInstDecl :: LTyClDecl Name -> TcM (Maybe TyThing) -- Nothing if error
tcFamInstDecl (L loc decl)
= -- Prime error recovery, set source location
-- (2) type check type equation
; tcTyVarBndrs k_tvs $ \t_tvs -> do { -- turn kinded into proper tyvars
-- (2) type check type equation
; tcTyVarBndrs k_tvs $ \t_tvs -> do { -- turn kinded into proper tyvars
; stupid_theta <- tcHsKindedContext k_ctxt
-- (3) Check that
-- - left-hand side contains no type family applications
-- (vanilla synonyms are fine, though, and we checked for
-- foralls earlier)
; stupid_theta <- tcHsKindedContext k_ctxt
-- (3) Check that
-- - left-hand side contains no type family applications
-- (vanilla synonyms are fine, though, and we checked for
-- foralls earlier)
-- type functions can have a higher-kinded result
; let resultKind = mkArrowKinds (drop (length hs_typats) kinds) resKind
-- type functions can have a higher-kinded result
; let resultKind = mkArrowKinds (drop (length hs_typats) kinds) resKind
= do { -- First extend the kind env with each data type, class, and
-- indexed type, mapping them to a type variable
let initialKindDecls = concat [allDecls decl | L _ decl <- alg_decls]
= do { -- First extend the kind env with each data type, class, and
-- indexed type, mapping them to a type variable
let initialKindDecls = concat [allDecls decl | L _ decl <- alg_decls]
; tcExtendKindEnv alg_kinds $ do
-- Now kind-check the type synonyms, in dependency order
; tcExtendKindEnv alg_kinds $ do
-- Now kind-check the type synonyms, in dependency order
-- returning kind-annotated decls; we don't kind-check
-- instances of indexed types yet, but leave this to
-- `tcInstDecls1'
-- returning kind-annotated decls; we don't kind-check
-- instances of indexed types yet, but leave this to
-- `tcInstDecls1'
(filter (not . isFamInstDecl . unLoc) alg_decls)
; return (kc_syn_decls, kc_alg_decls) }}}
(filter (not . isFamInstDecl . unLoc) alg_decls)
; return (kc_syn_decls, kc_alg_decls) }}}
= kcTyClDeclBody decl $ \ tvs' ->
do { is_boot <- tcIsHsBoot
; ctxt' <- kcHsContext ctxt
= kcTyClDeclBody decl $ \ tvs' ->
do { is_boot <- tcIsHsBoot
; ctxt' <- kcHsContext ctxt
; return (decl {tcdTyVars = tvs', tcdCtxt = ctxt', tcdSigs = sigs',
tcdATs = ats'}) }
where
; return (decl {tcdTyVars = tvs', tcdCtxt = ctxt', tcdSigs = sigs',
tcdATs = ats'}) }
where
kcDataDecl decl@(TyData {tcdND = new_or_data, tcdCtxt = ctxt, tcdCons = cons})
tvs
= do { ctxt' <- kcHsContext ctxt
kcDataDecl decl@(TyData {tcdND = new_or_data, tcdCtxt = ctxt, tcdCons = cons})
tvs
= do { ctxt' <- kcHsContext ctxt
; return (decl {tcdTyVars = tvs, tcdCtxt = ctxt', tcdCons = cons'}) }
where
-- doc comments are typechecked to Nothing here
; return (decl {tcdTyVars = tvs, tcdCtxt = ctxt', tcdCons = cons'}) }
where
-- doc comments are typechecked to Nothing here
; return (PrefixCon btys') }
kc_con_details (InfixCon bty1 bty2)
= do { bty1' <- kc_larg_ty bty1
; bty2' <- kc_larg_ty bty2
; return (InfixCon bty1' bty2') }
kc_con_details (RecCon fields)
; return (PrefixCon btys') }
kc_con_details (InfixCon bty1 bty2)
= do { bty1' <- kc_larg_ty bty1
; bty2' <- kc_larg_ty bty2
; return (InfixCon bty1' bty2') }
kc_con_details (RecCon fields)
; unbox_strict <- doptM Opt_UnboxStrictFields
; empty_data_decls <- doptM Opt_EmptyDataDecls
; kind_signatures <- doptM Opt_KindSignatures
; unbox_strict <- doptM Opt_UnboxStrictFields
; empty_data_decls <- doptM Opt_EmptyDataDecls
; kind_signatures <- doptM Opt_KindSignatures
-- Check that we don't use GADT syntax in H98 world
; checkTc (gadt_ok || h98_syntax) (badGadtDecl tc_name)
-- Check that we don't use GADT syntax in H98 world
; checkTc (gadt_ok || h98_syntax) (badGadtDecl tc_name)
tcdFDs = fundeps, tcdSigs = sigs, tcdATs = ats} )
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
tcdFDs = fundeps, tcdSigs = sigs, tcdATs = ats} )
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
- ; fds' <- mappM (addLocM tc_fundep) fundeps
- ; atss <- mappM (addLocM (tcTyClDecl1 (const Recursive))) ats
+ ; fds' <- mapM (addLocM tc_fundep) fundeps
+ ; atss <- mapM (addLocM (tcTyClDecl1 (const Recursive))) ats
-- NB: 'ats' only contains "type family" and "data family"
-- declarations as well as type family defaults
; let ats' = zipWith setTyThingPoss atss (map (tcdTyVars . unLoc) ats)
-- NB: 'ats' only contains "type family" and "data family"
-- declarations as well as type family defaults
; let ats' = zipWith setTyThingPoss atss (map (tcdTyVars . unLoc) ats)
- tc_fundep (tvs1, tvs2) = do { tvs1' <- mappM tcLookupTyVar tvs1 ;
- ; tvs2' <- mappM tcLookupTyVar tvs2 ;
+ tc_fundep (tvs1, tvs2) = do { tvs1' <- mapM tcLookupTyVar tvs1 ;
+ ; tvs2' <- mapM tcLookupTyVar tvs2 ;
; return (tvs1', tvs2') }
-- For each AT argument compute the position of the corresponding class
; return (tvs1', tvs2') }
-- For each AT argument compute the position of the corresponding class
(ConDecl name _ tvs ctxt details res_ty _)
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
(ConDecl name _ tvs ctxt details res_ty _)
= tcTyVarBndrs tvs $ \ tvs' -> do
{ ctxt' <- tcHsKindedContext ctxt
; (univ_tvs, ex_tvs, eq_preds, data_tc) <- tcResultType tycon tc_tvs tvs' res_ty
; let
-- Tiresome: tidy the tyvar binders, since tc_tvs and tvs' may have the same OccNames
tc_datacon is_infix field_lbls btys
= do { let bangs = map getBangStrictness btys
; (univ_tvs, ex_tvs, eq_preds, data_tc) <- tcResultType tycon tc_tvs tvs' res_ty
; let
-- Tiresome: tidy the tyvar binders, since tc_tvs and tvs' may have the same OccNames
tc_datacon is_infix field_lbls btys
= do { let bangs = map getBangStrictness btys
; failM } -- Give up now, because later checkValidTyCl
-- will loop if the synonym is recursive
where
; failM } -- Give up now, because later checkValidTyCl
-- will loop if the synonym is recursive
where
- = -- Check the context on the data decl
- checkValidTheta (DataTyCtxt name) (tyConStupidTheta tc) `thenM_`
+ = do -- Check the context on the data decl
+ checkValidTheta (DataTyCtxt name) (tyConStupidTheta tc)
addErrCtxt (dataConCtxt con) $
do { checkTc (dataConTyCon con == tc) (badDataConTyCon con)
; checkValidType ctxt (dataConUserType con)
addErrCtxt (dataConCtxt con) $
do { checkTc (dataConTyCon con == tc) (badDataConTyCon con)
; checkValidType ctxt (dataConUserType con)
- ; ifM (isNewTyCon tc) (checkNewDataCon con)
+ ; checkValidMonoType (dataConOrigResTy con)
+ -- Disallow MkT :: T (forall a. a->a)
+ -- Reason: it's really the argument of an equality constraint
+ ; when (isNewTyCon tc) (checkNewDataCon con)
-- Check that if the class has generic methods, then the
-- class has only one parameter. We can't do generic
-- Check that if the class has generic methods, then the
-- class has only one parameter. We can't do generic
= vcat [ ptext SLIT("Illegal generalised algebraic data declaration for") <+> quotes (ppr tc_name)
, nest 2 (parens $ ptext SLIT("Use -XGADTs to allow GADTs")) ]
= vcat [ ptext SLIT("Illegal generalised algebraic data declaration for") <+> quotes (ppr tc_name)
, nest 2 (parens $ ptext SLIT("Use -XGADTs to allow GADTs")) ]