From 0a07bb2f351aa3315fde0768db723650f23c31b6 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Mon, 27 Feb 2006 13:47:05 +0000 Subject: [PATCH] typechecker finds redeclaration of a variable --- Typecheck.hs | 4 +++- examples/typeerror-redecl | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 examples/typeerror-redecl diff --git a/Typecheck.hs b/Typecheck.hs index 6e845ba..ec40b1f 100644 --- a/Typecheck.hs +++ b/Typecheck.hs @@ -70,7 +70,9 @@ typeCheckStm (SDecl t i e) = do t2 <- typeCheckExp e if t == t2 || t2 == NoType then do m <- get - put (insert i t m) + case insertLookupWithKey (\k a1 a2 -> a1) i t m of + (Nothing,m') -> put m' + _ -> fail $ "Duplicate variable declaration: "++show i return NoType else fail $ "Illegal to assign an expression of type "++show t2++" to variable "++show i++" of type "++show t typeCheckStm (SPrint e) = do diff --git a/examples/typeerror-redecl b/examples/typeerror-redecl new file mode 100644 index 0000000..c96734e --- /dev/null +++ b/examples/typeerror-redecl @@ -0,0 +1,2 @@ +int a = 0; +int a = 5; -- 2.39.2