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