X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Frename%2FRnSource.lhs;h=606139b116b62824e4ed3a05f2fb4532d9d252cb;hb=202ac08f3e2afde0620e889cc81a95b2fd0ad9e1;hp=e29c2fefe200d572f66f100c2b9a843438d61c62;hpb=839a0880ea32b3ef2f0715957bfeec6e4bb3367b;p=ghc-hetmet.git diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs index e29c2fe..606139b 100644 --- a/compiler/rename/RnSource.lhs +++ b/compiler/rename/RnSource.lhs @@ -43,7 +43,7 @@ import SrcLoc ( Located(..), unLoc, noLoc ) import DynFlags ( DynFlag(..) ) import Maybes ( seqMaybe ) import Maybe ( isNothing, isJust ) -import Monad ( liftM ) +import Monad ( liftM, when ) import BasicTypes ( Boxity(..) ) \end{code} @@ -280,7 +280,7 @@ rnSrcInstDecl (InstDecl inst_ty mbinds uprags ats) -- The typechecker (not the renamer) checks that all -- the declarations are for the right class let - at_doc = text "In the associated types in an instance declaration" + at_doc = text "In the associated types of an instance declaration" at_names = map (head . tyClDeclNames . unLoc) ats in checkDupNames at_doc at_names `thenM_` @@ -787,8 +787,11 @@ rnATs ats = mapFvRn (wrapLocFstM rn_at) ats rnTyClDecl tydecl rn_at _ = panic "RnSource.rnATs: invalid TyClDecl" - lookupIdxVars _ tyvars cont = mappM lookupIdxVar tyvars >>= cont - -- + lookupIdxVars _ tyvars cont = + do { checkForDups tyvars; + ; tyvars' <- mappM lookupIdxVar tyvars + ; cont tyvars' + } -- Type index variables must be class parameters, which are the only -- type variables in scope at this point. lookupIdxVar (L l tyvar) = @@ -796,9 +799,27 @@ rnATs ats = mapFvRn (wrapLocFstM rn_at) ats name' <- lookupOccRn (hsTyVarName tyvar) return $ L l (replaceTyVarName tyvar name') + -- Type variable may only occur once. + -- + checkForDups [] = return () + checkForDups (L loc tv:ltvs) = + do { setSrcSpan loc $ + when (hsTyVarName tv `ltvElem` ltvs) $ + addErr (repeatedTyVar tv) + ; checkForDups ltvs + } + + rdrName `ltvElem` [] = False + rdrName `ltvElem` (L _ tv:ltvs) + | rdrName == hsTyVarName tv = True + | otherwise = rdrName `ltvElem` ltvs + noPatterns = text "Default definition for an associated synonym cannot have" <+> text "type pattern" +repeatedTyVar tv = ptext SLIT("Illegal repeated type variable") <+> + quotes (ppr tv) + -- This data decl will parse OK -- data T = a Int -- treating "a" as the constructor.