summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)