summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel M T Chakravarty <chak@cse.unsw.edu.au>2006-09-18 23:15:42 +0000
committerManuel M T Chakravarty <chak@cse.unsw.edu.au>2006-09-18 23:15:42 +0000
commit60f4aa3d033451da1daed159d9cb8780bf56e724 (patch)
tree9328213e1a44a996004a7f1e68cde23c53b088b8
parent5537ba01a8cd93ea209ef67f3431d9f5f9cd9d34 (diff)
downloadhaskell-60f4aa3d033451da1daed159d9cb8780bf56e724.tar.gz
Check for repeated tyvars in AT family decls
Sat Aug 26 19:49:55 EDT 2006 Manuel M T Chakravarty <chak@cse.unsw.edu.au> * Check for repeated tyvars in AT family decls
-rw-r--r--compiler/rename/RnSource.lhs27
1 files changed, 24 insertions, 3 deletions
diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs
index e29c2fefe2..344ae358c1 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}
@@ -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.