From c51d5393aa79b640d188b28f6226ba51118a622a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 29 Jan 2017 09:17:33 +0100 Subject: Detect duplicate variables --- check.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3-54-g00ecf