diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-04 08:21:31 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-04 08:21:31 +0100 |
commit | a33620210a161a20b60a138a0b984a5336a45f2d (patch) | |
tree | 1a7822d9ec513a9578b8c7e87d4748f3434c8e74 /src/Compiler.hs | |
parent | 1942efe3c45c87ef4f1c73d6078ff6487b820b53 (diff) | |
download | micro-lang-hs-a33620210a161a20b60a138a0b984a5336a45f2d.tar.gz micro-lang-hs-a33620210a161a20b60a138a0b984a5336a45f2d.zip |
Type-checking variable declaration
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r-- | src/Compiler.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Compiler.hs b/src/Compiler.hs index f36083c..40e5f73 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -153,7 +153,16 @@ compile x = do if not (definedType typ) then Error UndefinedType ("undefined type in variable declaration \"" ++ ident ++ "\"") pos : errs else errs - -- TODO: typecheck value + -- type-check value + vt <- compile val + errs <- case vt of + Right (Just t) -> + if t == typ + then return $ errs + else return $ (Error TypeError ("value type mismatch\n found: " ++ show t ++ "\n expected: " ++ show typ) pos) : errs + _ -> do + (_, errs) <- get -- error resolving value + return $ errs put (ev, errs) return $ Right $ Just typ (A.Return value pos) -> do |