X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fparser%2FRdrHsSyn.lhs;h=ac1a02826d6b803b4d5f00592e91f0b8af4d3236;hp=ef761e6d69154adeecd02661364d91e4066efc51;hb=c9bb6b63aa1f479a3dd3679c7e4c2c69471a4912;hpb=770f05e6d160874d607e3f2bbc57912319f2a104 diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs index ef761e6..ac1a028 100644 --- a/compiler/parser/RdrHsSyn.lhs +++ b/compiler/parser/RdrHsSyn.lhs @@ -70,6 +70,7 @@ import FastString import Maybes import Control.Applicative ((<$>)) +import Control.Monad import Text.ParserCombinators.ReadP as ReadP import Data.List ( nubBy ) import Data.Char @@ -172,13 +173,14 @@ Similarly for mkConDecl, mkClassOpSig and default-method names. \begin{code} mkClassDecl :: SrcSpan - -> Located (LHsContext RdrName, LHsType RdrName) + -> Located (Maybe (LHsContext RdrName), LHsType RdrName) -> Located [Located (FunDep RdrName)] -> Located (OrdList (LHsDecl RdrName)) -> P (LTyClDecl RdrName) -mkClassDecl loc (L _ (cxt, tycl_hdr)) fds where_cls +mkClassDecl loc (L _ (mcxt, tycl_hdr)) fds where_cls = do { let (binds, sigs, ats, docs) = cvBindsAndSigs (unLoc where_cls) + ; let cxt = fromMaybe (noLoc []) mcxt ; (cls, tparams) <- checkTyClHdr tycl_hdr ; tyvars <- checkTyVars tparams -- Only type vars allowed ; checkKindSigs ats @@ -189,14 +191,16 @@ mkClassDecl loc (L _ (cxt, tycl_hdr)) fds where_cls mkTyData :: SrcSpan -> NewOrData -> Bool -- True <=> data family instance - -> Located (LHsContext RdrName, LHsType RdrName) + -> Located (Maybe (LHsContext RdrName), LHsType RdrName) -> Maybe Kind -> [LConDecl RdrName] -> Maybe [LHsType RdrName] -> P (LTyClDecl RdrName) -mkTyData loc new_or_data is_family (L _ (cxt, tycl_hdr)) ksig data_cons maybe_deriv +mkTyData loc new_or_data is_family (L _ (mcxt, tycl_hdr)) ksig data_cons maybe_deriv = do { (tc, tparams) <- checkTyClHdr tycl_hdr + ; checkDatatypeContext mcxt + ; let cxt = fromMaybe (noLoc []) mcxt ; (tyvars, typats) <- checkTParams is_family tparams ; return (L loc (TyData { tcdND = new_or_data, tcdCtxt = cxt, tcdLName = tc, tcdTyVars = tyvars, tcdTyPats = typats, @@ -521,6 +525,13 @@ checkTyVars tparms = mapM chk tparms chk (L l _) = parseError l "Type found where type variable expected" +checkDatatypeContext :: Maybe (LHsContext RdrName) -> P () +checkDatatypeContext Nothing = return () +checkDatatypeContext (Just (L loc _)) + = do allowed <- extension datatypeContextsEnabled + unless allowed $ + parseError loc "Illegal datatype context (use -XDatatypeContexts)" + checkTyClHdr :: LHsType RdrName -> P (Located RdrName, -- the head symbol (type or class name) [LHsType RdrName]) -- parameters of head symbol