diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 09:17:33 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 09:17:33 +0100 |
commit | c51d5393aa79b640d188b28f6226ba51118a622a (patch) | |
tree | 4321a94af74c7b042cab360b1fc366a5327d94bf | |
parent | 9579a6f7e4693262341271afee01a70f23e95824 (diff) |
Detect duplicate variables
-rw-r--r-- | check.hs | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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) |