X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Frename%2FRnTypes.lhs;h=34a19a33c762fa19e416ef00964a17e6b3727f3b;hb=72e37dedee9e8a109ebda4b13e49b7133b530591;hp=d7d435ce974d97c2d0df0ad116ef0939b78539c6;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/rename/RnTypes.lhs b/compiler/rename/RnTypes.lhs index d7d435c..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} @@ -416,7 +421,14 @@ checkPrecMatch True op (MatchGroup ms _) = checkPrec op (unLoc p1) False `thenM_` checkPrec op (unLoc p2) True - check _ = panic "checkPrecMatch" + check _ = return () + -- This can happen. Consider + -- a `op` True = ... + -- op = ... + -- The infix flag comes from the first binding of the group + -- but the second eqn has no args (an error, but not discovered + -- until the type checker). So we don't want to crash on the + -- second eqn. checkPrec op (ConPatIn op1 (InfixCon _ _)) right = lookupFixityRn op `thenM` \ op_fix@(Fixity op_prec op_dir) -> @@ -493,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} @@ -528,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 @@ -569,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) @@ -662,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} @@ -723,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} @@ -745,12 +771,14 @@ checkTupSize tup_size forAllWarn doc ty (L loc tyvar) = ifOptM Opt_WarnUnusedMatches $ - setSrcSpan loc $ - addWarn (sep [ptext SLIT("The universally quantified type variable") <+> quotes (ppr tyvar), - nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))] + addWarnAt loc (sep [ptext SLIT("The universally quantified type variable") <+> quotes (ppr tyvar), + nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))] $$ - doc - ) + 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 '\''