Commit 67959071 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Improved warning messages in precedence check

parent b183d199
......@@ -85,10 +85,10 @@ bindPrecs :: [Decl] -> PCM ()
bindPrecs ds = case findDouble opFixDecls of
Just op -> report $ errDuplicatePrecedence op
Nothing -> case filter (`notElem` bvs) opFixDecls of
op : _ -> report $ errUndefinedOperator op
[] -> do
m <- getModuleIdent
modifyPrecEnv $ \ env -> foldr (bindPrec m) env fixDs
ops -> mapM_ (report . errUndefinedOperator) ops
where
(fixDs, nonFixDs) = partition isInfixDecl ds
opFixDecls = [ op | InfixDecl _ _ _ ops <- fixDs, op <- ops]
......@@ -349,7 +349,7 @@ fixPrecT :: (Pattern -> QualIdent -> Pattern -> Pattern)
fixPrecT infixpatt t1@(NegativePattern uop _) op t2 = do
OpPrec fix pr <- prec op <$> getPrecEnv
unless (pr < 6 || pr == 6 && fix == InfixL) $
report $ errInvalidParse "unary" uop op
report $ errInvalidParse "unary operator" uop op
fixRPrecT infixpatt t1 op t2
fixPrecT infixpatt t1 op t2 = fixRPrecT infixpatt t1 op t2
......@@ -357,7 +357,7 @@ fixRPrecT :: (Pattern -> QualIdent -> Pattern -> Pattern)
-> Pattern -> QualIdent -> Pattern -> PCM Pattern
fixRPrecT infixpatt t1 op t2@(NegativePattern uop _) = do
OpPrec _ pr <- prec op <$> getPrecEnv
unless (pr < 6) $ report $ errInvalidParse "unary" uop op
unless (pr < 6) $ report $ errInvalidParse "unary operator" uop op
return $ infixpatt t1 op t2
fixRPrecT infixpatt t1 op1 (InfixPattern t2 op2 t3) = do
OpPrec fix1 pr1 <- prec op1 <$> getPrecEnv
......@@ -418,7 +418,7 @@ checkOpL :: Ident -> Pattern -> PCM Pattern
checkOpL op t@(NegativePattern uop _) = do
OpPrec fix pr <- prec (qualify op) <$> getPrecEnv
unless (pr < 6 || pr == 6 && fix == InfixL) $
report $ errInvalidParse "unary" uop (qualify op)
report $ errInvalidParse "unary operator" uop (qualify op)
return t
checkOpL op1 t@(InfixPattern _ op2 _) = do
OpPrec fix1 pr1 <- prec (qualify op1) <$> getPrecEnv
......@@ -431,7 +431,7 @@ checkOpL _ t = return t
checkOpR :: Ident -> Pattern -> PCM Pattern
checkOpR op t@(NegativePattern uop _) = do
OpPrec _ pr <- prec (qualify op) <$> getPrecEnv
when (pr >= 6) $ report $ errInvalidParse "unary" uop (qualify op)
when (pr >= 6) $ report $ errInvalidParse "unary operator" uop (qualify op)
return t
checkOpR op1 t@(InfixPattern _ op2 _) = do
OpPrec fix1 pr1 <- prec (qualify op1) <$> getPrecEnv
......@@ -464,18 +464,18 @@ prec op env = case qualLookupP op env of
errUndefinedOperator :: Ident -> Message
errUndefinedOperator op = posMessage op $ hsep $ map text
["No definition for", idName op, "in this scope"]
["No definition for", escName op, "in this scope"]
errDuplicatePrecedence :: Ident -> Message
errDuplicatePrecedence op = posMessage op $ hsep $ map text
["More than one fixity declaration for", idName op]
["More than one fixity declaration for", escName op]
errInvalidParse :: String -> Ident -> QualIdent -> Message
errInvalidParse what op1 op2 = posMessage op1 $ hsep $ map text
[ "Invalid use of", what, idName op1, "with", qualName op2
[ "Invalid use of", what, escName op1, "with", escQualName op2, "in"
, showLine $ qidPosition op2]
errAmbiguousParse :: String -> QualIdent -> QualIdent -> Message
errAmbiguousParse what op1 op2 = posMessage op1 $ hsep $ map text
["Ambiguous use of", what, qualName op1, "with", qualName op2
["Ambiguous use of", what, escQualName op1, "with", escQualName op2, "in"
, showLine $ qidPosition op2]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment