]> ruin.nu Git - proglang.git/blobdiff - Typecheck.hs
typechecker finds redeclaration of a variable
[proglang.git] / Typecheck.hs
index 6e845ba2cb56b9625570676c65e6354da53eb4ba..ec40b1f0bc7dc8e249e6e95b738ac3a85bbb2077 100644 (file)
@@ -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