@@ -490,12 +490,24 @@ pFixity = do pushIndent
490490 pTerminator
491491 let prec = fromInteger i
492492 istate <- getState
493− let fs = map (Fix (f prec)) ops
494− setState (istate {
495− idris_infixes = nub $ sort (fs ++ idris_infixes istate),
496− ibc_write = map IBCFix fs ++ ibc_write istate })
497− fc <- pfc
498− return (PFix fc (f prec) ops)
493+ let infixes = idris_infixes istate
494+ let fs = map (Fix (f prec)) ops
495+ let redecl = map (alreadyDeclared infixes) fs
496+ if False `notElem` map checkValidity redecl
497+ then do setState (istate { idris_infixes = nub $ sort (fs ++ infixes)
498+ , ibc_write = map IBCFix fs ++ ibc_write istate
499+ })
500+ fc <- pfc
501+ return (PFix fc (f prec) ops)
502+ else fail "Illegal redeclaration of fixity"
503+ where alreadyDeclared :: [FixDecl] -> FixDecl -> (FixDecl, [FixDecl])
504+ alreadyDeclared fs f = (f, filter ((extractName f ==) . extractName) fs)
505+
506+ checkValidity :: (FixDecl, [FixDecl]) -> Bool
507+ checkValidity (f, fs) = all (== f) fs
508+
509+ extractName :: FixDecl -> String
510+ extractName (Fix _ n) = n
499511
500512fixity :: IParser (Int -> Fixity)
501513fixity = try (do reserved "infixl"; return Infixl)