diff options
-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) |