on master help sign in
Make pattern exhaustive, giving parse error when someone uses binops with different associativity
commitcd84e066955e99799c563576ce7edc0069753c61 authorEvan Czaplicki <info@elm-lang.org> dateTue 13 Aug 2013, 22:20 (13 years ago) parent47d68d8
1 file changed+6−4
compiler/Parse/Binop.hs+6−4
compiler/Parse/Binop.hs+6−4
@@ -93,12 +93,14 @@ getAssoc table n eops
9393 | all (==L) assocs = return L
9494 | all (==R) assocs = return R
9595 | all (==N) assocs = case assocs of [_] -> return N
96− _ -> fail msg
96+ _ -> fail (msg "precedence")
97+ | otherwise = fail (msg "associativity")
9798 where levelOps = filter (hasLevel table n) eops
9899 assocs = map (opAssoc table . fst) levelOps
99− msg = concat [ "Conflicting precedence for binary operators ("
100− , intercalate ", " (map fst eops), "). "
101− , "Consider adding parentheses to disambiguate." ]
100+ msg problem =
101+ concat [ "Conflicting " ++ problem ++ " for binary operators ("
102+ , intercalate ", " (map fst eops), "). "
103+ , "Consider adding parentheses to disambiguate." ]
102104
103105infixStmt :: IParser (Int, Assoc, String)
104106infixStmt =