summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-29 09:17:33 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-29 09:17:33 +0100
commitc51d5393aa79b640d188b28f6226ba51118a622a (patch)
tree4321a94af74c7b042cab360b1fc366a5327d94bf
parent9579a6f7e4693262341271afee01a70f23e95824 (diff)
Detect duplicate variables
-rw-r--r--check.hs5
1 files changed, 4 insertions, 1 deletions
diff --git a/check.hs b/check.hs
index d2a7c92..1a0a24c 100644
--- a/check.hs
+++ b/check.hs
@@ -91,7 +91,10 @@ typeCheck (Program decls) = Program <$> mapM (goD topLevelNames) decls
goS :: Type -- function return type
-> Map.Map Name Type -> Statement -> Error (Map.Map Name Type, Statement)
- goS _ names st@(StVarDeclaration t n Nothing) = return (Map.insert n t names, st)
+ goS _ names st@(StVarDeclaration t n Nothing) = do
+ maybe (return (Map.insert n t names, st))
+ (const $ Left $ "Duplicate variable '" ++ n ++ "'")
+ (Map.lookup n names)
goS frt names (StVarDeclaration t n (Just e)) = do
(newnames, _) <- goS frt names (StVarDeclaration t n Nothing)
(_, StAssignment _ newe) <- goS frt newnames (StAssignment n e)