diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 09:17:54 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 09:18:08 +0100 |
commit | af1523e4b51f432d3df4d2e2ae57de95e3440d12 (patch) | |
tree | 3fdf535d3e702cd04ee2d5f0a6b58482e119a4c6 | |
parent | c51d5393aa79b640d188b28f6226ba51118a622a (diff) |
Do function argument typechecking correctly
-rw-r--r-- | check.hs | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -137,20 +137,20 @@ typeCheck (Program decls) = Program <$> mapM (goD topLevelNames) decls goE _ (ExLit l@(LitString _) _) = return $ ExLit l $ Just (TypePtr (TypeInt 8)) goE names (ExLit l@(LitVar n) _) = maybe (Left $ "Undefined variable '" ++ n ++ "'") (return . ExLit l . Just) (Map.lookup n names) - goE names (ExLit l@(LitCall n args) _) = do + goE names (ExLit (LitCall n args) _) = do ft <- maybe (Left $ "Unknown function '" ++ n ++ "'") return $ Map.lookup n functionTypes rargs <- mapM (goE names) args when (length rargs /= length (snd ft)) $ Left ("Expected " ++ show (length (snd ft)) ++ "arguments to " ++ "function '" ++ n ++ "', but got " ++ show (length rargs)) >> return () - flip mapM_ rargs $ - \a -> let argtype = fromJust (exTypeOf a) - in if canConvert argtype (fst ft) - then return a - else Left $ "Cannot convert type '" ++ pshow argtype ++ "' to '" ++ pshow (fst ft) - ++ "' in call of function '" ++ pshow n ++ "'" - return $ ExLit l (Just (fst ft)) + flip mapM_ (zip rargs [0..]) $ + \(a,i) -> let argtype = fromJust (exTypeOf a) + in if canConvert argtype (snd ft !! i) + then return a + else Left $ "Cannot convert type '" ++ pshow argtype ++ "' to '" ++ pshow (fst ft) + ++ "' in call of function '" ++ pshow n ++ "'" + return $ ExLit (LitCall n rargs) (Just (fst ft)) goE names (ExBinOp bo e1 e2 _) = do re1 <- goE names e1 re2 <- goE names e2 |