X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Frename%2FRnTypes.lhs;h=34a19a33c762fa19e416ef00964a17e6b3727f3b;hb=90dc9026b091be5cca5da4c6cbd3713ecc493361;hp=055cd349ad77a701672a6832c56467d78c1f5bc6;hpb=39fd94e2727715556805a85a7e803c337df950a9;p=ghc-hetmet.git diff --git a/compiler/rename/RnTypes.lhs b/compiler/rename/RnTypes.lhs index 055cd34..34a19a3 100644 --- a/compiler/rename/RnTypes.lhs +++ b/compiler/rename/RnTypes.lhs @@ -21,13 +21,14 @@ module RnTypes ( dupFieldErr, patSigErr, checkTupSize ) where -import DynFlags ( DynFlag(Opt_WarnUnusedMatches, Opt_GlasgowExts) ) +import DynFlags ( DynFlag(Opt_WarnUnusedMatches, Opt_GlasgowExts, Opt_ScopedTypeVariables, Opt_OverloadedStrings ) ) import HsSyn import RdrHsSyn ( extractHsRhoRdrTyVars ) import RnHsSyn ( extractHsTyNames, parrTyCon_name, tupleTyCon_name, listTyCon_name ) +import RnHsDoc ( rnLHsDoc ) import RnEnv ( lookupOccRn, lookupBndrRn, lookupSyntaxName, lookupLocatedOccRn, lookupLocatedBndrRn, lookupLocatedGlobalOccRn, bindTyVarsRn, @@ -39,7 +40,7 @@ import RdrName ( RdrName, elemLocalRdrEnv ) import PrelNames ( eqClassName, integralClassName, geName, eqName, negateName, minusName, lengthPName, indexPName, plusIntegerName, fromIntegerName, timesIntegerName, - ratioDataConName, fromRationalName ) + ratioDataConName, fromRationalName, fromStringName ) import TypeRep ( funTyCon ) import Constants ( mAX_TUPLE_SIZE ) import Name ( Name ) @@ -121,17 +122,16 @@ rnHsType doc (HsTyVar tyvar) = lookupOccRn tyvar `thenM` \ tyvar' -> returnM (HsTyVar tyvar') -rnHsType doc (HsOpTy ty1 (L loc op) ty2) - = setSrcSpan loc ( - lookupOccRn op `thenM` \ op' -> - let - l_op' = L loc op' - in - lookupTyFixityRn l_op' `thenM` \ fix -> - rnLHsType doc ty1 `thenM` \ ty1' -> - rnLHsType doc ty2 `thenM` \ ty2' -> - mkHsOpTyRn (\t1 t2 -> HsOpTy t1 l_op' t2) (ppr op') fix ty1' ty2' - ) +rnHsType doc ty@(HsOpTy ty1 (L loc op) ty2) + = setSrcSpan loc $ + do { ty_ops_ok <- doptM Opt_ScopedTypeVariables -- Badly named option + ; checkErr ty_ops_ok (opTyErr op ty) + ; op' <- lookupOccRn op + ; let l_op' = L loc op' + ; fix <- lookupTyFixityRn l_op' + ; ty1' <- rnLHsType doc ty1 + ; ty2' <- rnLHsType doc ty2 + ; mkHsOpTyRn (\t1 t2 -> HsOpTy t1 l_op' t2) (ppr op') fix ty1' ty2' } rnHsType doc (HsParTy ty) = rnLHsType doc ty `thenM` \ ty' -> @@ -189,6 +189,11 @@ rnHsType doc (HsSpliceTy _) = do { addErr (ptext SLIT("Type splices are not yet implemented")) ; failM } +rnHsType doc (HsDocTy ty haddock_doc) + = rnLHsType doc ty `thenM` \ ty' -> + rnLHsDoc haddock_doc `thenM` \ haddock_doc' -> + returnM (HsDocTy ty' haddock_doc') + rnLHsTypes doc tys = mappM (rnLHsType doc) tys \end{code} @@ -500,14 +505,20 @@ rnLPred :: SDoc -> LHsPred RdrName -> RnM (LHsPred Name) rnLPred doc = wrapLocM (rnPred doc) rnPred doc (HsClassP clas tys) - = lookupOccRn clas `thenM` \ clas_name -> - rnLHsTypes doc tys `thenM` \ tys' -> - returnM (HsClassP clas_name tys') - + = do { clas_name <- lookupOccRn clas + ; tys' <- rnLHsTypes doc tys + ; returnM (HsClassP clas_name tys') + } +rnPred doc (HsEqualP ty1 ty2) + = do { ty1' <- rnLHsType doc ty1 + ; ty2' <- rnLHsType doc ty2 + ; returnM (HsEqualP ty1' ty2') + } rnPred doc (HsIParam n ty) - = newIPNameRn n `thenM` \ name -> - rnLHsType doc ty `thenM` \ ty' -> - returnM (HsIParam name ty') + = do { name <- newIPNameRn n + ; ty' <- rnLHsType doc ty + ; returnM (HsIParam name ty') + } \end{code} @@ -535,7 +546,6 @@ rnPatsAndThen ctxt pats thing_inside bindLocatedLocalsFV doc_pat bndrs $ \ new_bndrs -> rnLPats pats `thenM` \ (pats', pat_fvs) -> thing_inside pats' `thenM` \ (res, res_fvs) -> - let unused_binders = filter (not . (`elemNameSet` res_fvs)) new_bndrs in @@ -576,6 +586,10 @@ rnPat (SigPatIn pat ty) where doc = text "In a pattern type-signature" +rnPat (LitPat lit@(HsString s)) + = do { ovlStr <- doptM Opt_OverloadedStrings + ; if ovlStr then rnPat (mkNPat (mkHsIsString s) Nothing) + else do { rnLit lit; return (LitPat lit, emptyFVs) } } -- Same as below rnPat (LitPat lit) = rnLit lit `thenM_` returnM (LitPat lit, emptyFVs) @@ -669,21 +683,22 @@ rnConPat con (InfixCon pat1 pat2) -- ----------------------------------------------------------------------------- -- rnRpats -rnRpats :: [(Located RdrName, LPat RdrName)] - -> RnM ([(Located Name, LPat Name)], FreeVars) +-- Haddock comments for record fields are renamed to Nothing here +rnRpats :: [HsRecField RdrName (LPat RdrName)] + -> RnM ([HsRecField Name (LPat Name)], FreeVars) rnRpats rpats = mappM_ field_dup_err dup_fields `thenM_` mapFvRn rn_rpat rpats `thenM` \ (rpats', fvs) -> returnM (rpats', fvs) where - (_, dup_fields) = removeDups compare [ unLoc f | (f,_) <- rpats ] + (_, dup_fields) = removeDups compare [ unLoc f | HsRecField f _ _ <- rpats ] field_dup_err dups = addErr (dupFieldErr "pattern" dups) - rn_rpat (field, pat) + rn_rpat (HsRecField field pat _) = lookupLocatedGlobalOccRn field `thenM` \ fieldname -> rnLPat pat `thenM` \ (pat', fvs) -> - returnM ((fieldname, pat'), fvs `addOneFV` unLoc fieldname) + returnM ((mkRecField fieldname pat'), fvs `addOneFV` unLoc fieldname) \end{code} @@ -730,6 +745,10 @@ rnOverLit (HsFractional i _) -- and denominator (see DsUtils.mkIntegerLit) in returnM (HsFractional i from_rat_name, fvs `plusFV` extra_fvs) + +rnOverLit (HsIsString s _) + = lookupSyntaxName fromStringName `thenM` \ (from_string_name, fvs) -> + returnM (HsIsString s from_string_name, fvs) \end{code} @@ -757,6 +776,10 @@ forAllWarn doc ty (L loc tyvar) $$ doc) +opTyErr op ty + = hang (ptext SLIT("Illegal operator") <+> quotes (ppr op) <+> ptext SLIT("in type") <+> quotes (ppr ty)) + 2 (parens (ptext SLIT("Use -fscoped-type-variables to allow operators in types"))) + bogusCharError c = ptext SLIT("character literal out of range: '\\") <> char c <> char '\''